本文整理汇总了PHP中Assetic\Asset\AssetInterface::getTargetUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetInterface::getTargetUrl方法的具体用法?PHP AssetInterface::getTargetUrl怎么用?PHP AssetInterface::getTargetUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetInterface
的用法示例。
在下文中一共展示了AssetInterface::getTargetUrl方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process(AssetInterface $asset)
{
if (0 < preg_match($this->pattern, $asset->getTargetUrl())) {
$asset->ensureFilter($this->filter);
}
return $asset;
}
示例2: filterDump
public function filterDump(AssetInterface $asset)
{
$sourceUrl = $asset->getSourceUrl();
$targetUrl = $asset->getTargetUrl();
if (null === $sourceUrl || null === $targetUrl || $sourceUrl == $targetUrl) {
return;
}
// learn how to get from the target back to the source
if (false !== strpos($sourceUrl, '://')) {
// the source is absolute, this should be easy
$parts = parse_url($sourceUrl);
$host = $parts['scheme'] . '://' . $parts['host'];
$path = dirname($parts['path']) . '/';
} else {
// assume source and target are on the same host
$host = '';
// pop entries off the target until it fits in the source
if ('.' == dirname($sourceUrl)) {
$path = str_repeat('../', substr_count($targetUrl, '/'));
} elseif ('.' == ($targetDir = dirname($targetUrl))) {
$path = dirname($sourceUrl) . '/';
} else {
$path = '';
while (0 !== strpos($sourceUrl, $targetDir)) {
if (false !== ($pos = strrpos($targetDir, '/'))) {
$targetDir = substr($targetDir, 0, $pos);
$path .= '../';
} else {
$targetDir = '';
$path .= '../';
break;
}
}
$path .= substr(dirname($sourceUrl) . '/', strlen($targetDir) + 1);
}
}
$callback = function ($matches) use($host, $path) {
if (false !== strpos($matches['url'], '://')) {
// absolute
return $matches[0];
}
if ('/' == $matches['url'][0]) {
// root relative
return str_replace($matches['url'], $host . $matches['url'], $matches[0]);
}
// document relative
$url = $matches['url'];
while (0 === strpos($url, '../') && 2 <= substr_count($path, '/')) {
$path = substr($path, 0, strrpos(rtrim($path, '/'), '/') + 1);
$url = substr($url, 3);
}
return str_replace($matches['url'], $host . $path . $url, $matches[0]);
};
$content = $asset->getContent();
$content = preg_replace_callback('/url\\((["\']?)(?<url>.*)(\\1)\\)/', $callback, $content);
$content = preg_replace_callback('/import (["\'])(?<url>.*)(\\1)/', $callback, $content);
$asset->setContent($content);
}
示例3: process
public function process(AssetInterface $asset)
{
$targetUrl = $asset->getTargetUrl();
if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, '_controller/')) {
$asset->setTargetUrl('_controller/'.$targetUrl);
}
return $asset;
}
示例4: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
$compiler
->raw('isset($context[\'assetic\'][\'use_controller\']) && $context[\'assetic\'][\'use_controller\'] ? ')
->subcompile($this->getPathFunction($name))
->raw(' : ')
->subcompile($this->getAssetFunction($asset->getTargetUrl()))
;
}
示例5: writeAsset
public function writeAsset(AssetInterface $asset)
{
static::write($this->dir . '/' . $asset->getTargetUrl(), $asset->dump());
}
示例6: filterDump
public function filterDump(AssetInterface $asset)
{
$sourceUrl = $asset->getSourceUrl();
$targetUrl = $asset->getTargetUrl();
if (null === $sourceUrl || null === $targetUrl || $sourceUrl == $targetUrl) {
return;
}
// learn how to get from the target back to the source
if (false !== strpos($sourceUrl, '://')) {
// the source is absolute, this should be easy
$parts = parse_url($sourceUrl);
$host = $parts['scheme'].'://'.$parts['host'];
$path = dirname($parts['path']).'/';
} else {
// assume source and target are on the same host
$host = '';
// pop entries off the target until it fits in the source
$path = '';
$targetDir = dirname($targetUrl);
while (0 !== strpos($sourceUrl, $targetDir)) {
if (false !== $pos = strrpos($targetDir, '/')) {
$targetDir = substr($targetDir, 0, $pos);
$path .= '../';
} else {
throw new \RuntimeException(sprintf('Unable to calculate relative path from "%s" to "%s"', $targetUrl, $sourceUrl));
}
}
$path .= substr(dirname($sourceUrl).'/', strlen($targetDir) + 1);
}
$filter = function($url) use($host, $path)
{
if (false !== strpos($url, '://')) {
// absolute
return $url;
} elseif ('/' == $url[0]) {
// root relative
return $host.$url;
} else {
// document relative
while (0 === strpos($url, '../') && 2 <= substr_count($path, '/')) {
$path = substr($path, 0, strrpos(rtrim($path, '/'), '/') + 1);
$url = substr($url, 3);
}
return $host.$path.$url;
}
};
// tokenize and filter the asset content
$tokens = $this->tokenizer->tokenizeString($asset->getContent());
// cleanup the php tags codesniffer adds
$tokens = array_slice($tokens, 1, -1);
$token = array_pop($tokens);
if (' ' != $token['content']) {
$token['content'] = substr($token['content'], 0, -1);
$tokens[] = $token;
}
$content = '';
$inUrl = $inImport = 0;
for ($i = 0; $i < count($tokens); $i++) {
$token = $tokens[$i];
if (T_URL == $token['code']) {
$token['content'] = $filter($token['content']);
} elseif (T_STRING == $token['code'] && 'url' == $token['content']) {
$inUrl = 1;
} elseif (T_STRING == $token['code'] && 'import' == $token['content'] && isset($tokens[$i - 1]) && T_ASPERAND == $tokens[$i - 1]['code']) {
$inImport = 1;
} elseif (T_OPEN_PARENTHESIS == $token['code'] && 1 == $inUrl) {
$inUrl = 2;
} elseif (T_CONSTANT_ENCAPSED_STRING == $token['code'] && (2 == $inUrl || 1 == $inImport)) {
$quote = $token['content'][0];
$url = $filter(substr($token['content'], 1, -1));
$token['content'] = $quote.$url.$quote;
} elseif (T_WHITESPACE != $token['code']) {
$inUrl = $inImport = 0;
}
$content .= $token['content'];
}
$asset->setContent($content);
}
示例7: dumpAsset
/**
* Writes an asset.
*
* @param AssetInterface $asset An asset
* @param string $basePath The base directory to write to
* @param OutputInterface $output The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
protected function dumpAsset(AssetInterface $asset, $basePath, OutputInterface $output)
{
$target = rtrim($basePath, '/') . '/' . $asset->getTargetUrl();
if (!is_dir($dir = dirname($target))) {
$output->writeln('<info>[dir+]</info> '.$dir);
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory '.$dir);
}
}
$output->writeln('<info>[file+]</info> '.$target);
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file '.$target);
}
}
示例8: getAssetUrl
protected function getAssetUrl(AssetInterface $asset, $options = array())
{
return $asset->getTargetUrl();
}
示例9: getAssetUrl
protected function getAssetUrl(AssetInterface $asset, $options = array())
{
return $this->assetsHelper->getUrl($asset->getTargetUrl(), isset($options['package']) ? $options['package'] : null);
}
示例10: process
/**
* Processes an asset.
*
* @param AssetInterface $asset An asset
* @param Boolean $debug Debug mode
*/
public function process(AssetInterface $asset, $debug = false)
{
if ((null === $this->debug || $this->debug === $debug) && preg_match($this->pattern, $asset->getTargetUrl())) {
$asset->ensureFilter($this->filter);
}
}
示例11: loadRouteForAsset
/**
* Loads a route to serve an supplied asset.
*
* The fake front controller that {@link UseControllerWorker} adds to the
* target URL will be removed before set as a route pattern.
*
* @param RouteCollection $routes The route collection
* @param AssetInterface $asset The asset
* @param string $name The name to use
* @param integer $pos The leaf index
*/
private function loadRouteForAsset(RouteCollection $routes, AssetInterface $asset, $name, $pos = null)
{
$defaults = array(
'_controller' => 'assetic.controller:render',
'name' => $name,
'pos' => $pos,
);
// remove the fake front controller
$pattern = str_replace('_controller/', '', $asset->getTargetUrl());
if ($format = pathinfo($pattern, PATHINFO_EXTENSION)) {
$defaults['_format'] = $format;
}
$route = '_assetic_'.$name;
if (null !== $pos) {
$route .= '_'.$pos;
}
$routes->add($route, new Route($pattern, $defaults));
}
示例12: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
$compiler->repr($asset->getTargetUrl());
}