/** * Compiles the node * * @param Context $context The context * @param array|null $arguments Array of arguments * @param boolean|null $important Important flag * @return UrlNode */ public function compile(Context $context, $arguments = null, $important = null) { $value = $this->value->compile($context); if (!$this->isCompiled) { $rootPath = isset($this->currentFileInfo) && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false; if ($rootPath && is_string($value->value) && Util::isPathRelative($value->value)) { $quoteExists = self::propertyExists($value, 'quote'); if ($quoteExists && empty($value->quote) || !$quoteExists) { $rootPath = preg_replace_callback('/[\\(\\)\'"\\s]/', function ($match) { return '\\' . $match[0]; }, $rootPath); } $value->value = $rootPath . $value->value; } $value->value = Util::normalizePath($value->value, false); if ($context->urlArgs) { if (!preg_match('/^\\s*data:/', $value->value, $matches)) { $delimiter = strpos($value->value, '?') === false ? '?' : '&'; $urlArgs = $delimiter . $context->urlArgs; if (strpos($value->value, '#') !== false) { $value->value = str_replace('#', $urlArgs . '#', $value->value); } else { $value->value .= $urlArgs; } } } } return new UrlNode($value, $this->index, $this->currentFileInfo, true); }
/** * Returns the file path, takes care about relative urls * * @param string $path * @return mixed|string */ protected function getFilePath($path) { $path = Util::sanitizePath($path); if (Util::isPathRelative($path) && $this->currentFileInfo) { if ($this->context->relativeUrls) { $path = $this->currentFileInfo->currentDirectory . $path; } else { $path = $this->currentFileInfo->entryPath . $path; } $path = Util::normalizePath($path); } return $path; }
/** * Compiles the path * * @param Context $context * @return UrlNode */ public function compilePath(Context $context) { $path = $this->path->compile($context); if (!$path instanceof UrlNode) { $rootPath = $this->currentFileInfo && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false; if ($rootPath) { $pathValue = $path->value; // Add the base path if the import is relative if ($pathValue && Util::isPathRelative($pathValue)) { $path->value = $rootPath . $pathValue; } } $path->value = Util::normalizePath($path->value); } return $path; }