本文整理汇总了PHP中Webmozart\PathUtil\Path::isLocal方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::isLocal方法的具体用法?PHP Path::isLocal怎么用?PHP Path::isLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\PathUtil\Path
的用法示例。
在下文中一共展示了Path::isLocal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieve
/**
* {@inheritdoc}
*/
public function retrieve($uri)
{
if (isset($this->mappings[$uri])) {
$uri = $this->mappings[$uri];
if (Path::isLocal($uri)) {
$uri = 'file://' . ($this->baseDir ? Path::makeAbsolute($uri, $this->baseDir) : $uri);
}
$this->lastUsedRetriever = $this->filesystemRetriever;
return $this->filesystemRetriever->retrieve($uri);
}
$this->lastUsedRetriever = $this->fallbackRetriever;
return $this->fallbackRetriever->retrieve($uri);
}
示例2: filterReferences
public static function filterReferences($content, $callback)
{
return CssUtils::filterReferences($content, function ($matches) use($callback) {
// The referenced path is a repository path
// e.g. "/webmozart/puli/images/bg.png"
$referencedPath = $matches['url'];
// Ignore empty URLs
if ('' === $referencedPath) {
return $matches[0];
}
// Ignore non-local paths
if (!Path::isLocal($referencedPath)) {
return $matches[0];
}
// Ignore "data:" URLs
if (0 === strpos($referencedPath, 'data:')) {
return $matches[0];
}
// If the referenced path is not absolute, resolve it relative to
// the directory of the source file
if (!Path::isAbsolute($referencedPath)) {
$referencedPath = Path::makeAbsolute($referencedPath, $repoDir);
}
// The referenced asset must be known
if (!array_key_exists($referencedPath, $pathMap)) {
throw new AssetException(sprintf('The asset "%s" referenced in "%s" could not be found.', $matches['url'], $repoPath));
}
// The target path of the referenced file must be set
if (!$pathMap[$referencedPath]) {
throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $matches['url']));
}
// The target path of the source file must be set
if (!$targetPath) {
throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $repoPath));
}
// Get the relative path from the source directory to the reference
// e.g. "/css/style.css" + "/images/bg.png" = "../images/bg.png"
$relativePath = Path::makeRelative($pathMap[$referencedPath], $targetDir);
return str_replace($matches['url'], $relativePath, $matches[0]);
});
}
示例3: filterDump
/**
* Filters an asset just before it's dumped.
*
* @param AssetInterface $asset An asset
*/
public function filterDump(AssetInterface $asset)
{
if (!$asset instanceof PuliAsset) {
return;
}
$pathMap = array();
// Get a map of repository paths to target paths
// e.g. "/webmozart/puli/images/bg.png" => "/images/bg.png"
foreach ($this->am->getNames() as $name) {
$this->extractTargetPaths($this->am->get($name), $pathMap);
}
// Remember the repository dir of the current resource
$repoPath = $asset->getSourcePath();
$repoDir = Path::getDirectory($repoPath);
// Get the target directory of the current resource
// e.g. "css"
$targetPath = $asset->getTargetPath();
$targetDir = Path::getDirectory($targetPath);
// Convert to an absolute path so that we can create a proper
// relative path later on
// e.g. "/css"
if (!Path::isAbsolute($targetDir)) {
$targetDir = '/' . $targetDir;
}
$content = CssUtils::filterReferences($asset->getContent(), function ($matches) use($pathMap, $repoDir, $repoPath, $targetDir, $targetPath) {
// The referenced path is a repository path
// e.g. "/webmozart/puli/images/bg.png"
$referencedPath = $matches['url'];
// Ignore empty URLs
if ('' === $referencedPath) {
return $matches[0];
}
// Ignore non-local paths
if (!Path::isLocal($referencedPath)) {
return $matches[0];
}
// Ignore "data:" URLs
if (0 === strpos($referencedPath, 'data:')) {
return $matches[0];
}
// If the referenced path is not absolute, resolve it relative to
// the directory of the source file
if (!Path::isAbsolute($referencedPath)) {
$referencedPath = Path::makeAbsolute($referencedPath, $repoDir);
}
// The referenced asset must be known
if (!array_key_exists($referencedPath, $pathMap)) {
throw new AssetException(sprintf('The asset "%s" referenced in "%s" could not be found.', $referencedPath, $repoPath));
}
// The target path of the referenced file must be set
if (!$pathMap[$referencedPath]) {
throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $matches['url']));
}
// The target path of the source file must be set
if (!$targetPath) {
throw new AssetException(sprintf('The referenced path "%s" in "%s" cannot be resolved, because ' . 'the target path of "%s" is not set.', $matches['url'], $repoPath, $repoPath));
}
// Get the relative path from the source directory to the reference
// e.g. "/css/style.css" + "/images/bg.png" = "../images/bg.png"
$relativePath = Path::makeRelative($pathMap[$referencedPath], $targetDir);
return str_replace($matches['url'], $relativePath, $matches[0]);
});
$asset->setContent($content);
}
示例4: testIsLocalFailsIfInvalidPath
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The path must be a string. Got: array
*/
public function testIsLocalFailsIfInvalidPath()
{
Path::isLocal(array());
}