/** * 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); }
/** * @see Importer::getLastModified */ public function getLastModified($path, FileInfo $currentFileInfo) { $normalizedPath = Util::normalizePath($currentFileInfo->currentDirectory . $path); if (isset($this->files[$normalizedPath])) { $path = $normalizedPath; } if (isset($this->lastModified[$path])) { return $this->lastModified[$path]; } return false; }
/** * 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; }
/** * @covers normalizePath * @dataProvider getDataForNormalizePathTest */ public function testNormalizePath($path, $expected) { $this->assertEquals(Util::normalizePath($path), $expected); }
/** * Sets current file. * * @param string $file The path to a file */ public function setCurrentFile($file) { $file = Util::normalizePath($file); $dirname = preg_replace('/[^\\/\\\\]*$/', '', $file); $this->currentFileInfo = new FileInfo(['currentDirectory' => $dirname, 'filename' => $file, 'rootPath' => $this->currentFileInfo && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : $this->rootPath, 'entryPath' => $dirname]); }
/** * Normalizes the filename. * * @param string $filename * * @return string */ protected function normalizeFilename($filename) { $filename = Util::normalizePath($filename); if (($basePath = $this->getOption('base_path')) && ($pos = strpos($filename, $basePath)) !== false) { $filename = substr($filename, $pos + strlen($basePath)); if (strpos($filename, '/') === 0) { $filename = substr($filename, 1); } } return $this->getOption('root_path') . $filename; }