本文整理汇总了PHP中Assetic\Asset\AssetInterface::getSourceRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetInterface::getSourceRoot方法的具体用法?PHP AssetInterface::getSourceRoot怎么用?PHP AssetInterface::getSourceRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetInterface
的用法示例。
在下文中一共展示了AssetInterface::getSourceRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterLoad
/**
* Filters an asset after it has been loaded.
*
* @param \Assetic\Asset\AssetInterface $asset
* @return void
*/
public function filterLoad(AssetInterface $asset)
{
$max_nesting_level = ini_get('xdebug.max_nesting_level');
$memory_limit = ini_get('memory_limit');
if ($max_nesting_level && $max_nesting_level < 200) {
ini_set('xdebug.max_nesting_level', 200);
}
if ($memory_limit && $memory_limit < 256) {
ini_set('memory_limit', '256M');
}
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$dirs = array();
$lc = new \Less_Parser(array('compress' => true));
if ($root && $path) {
$dirs[] = dirname($root . '/' . $path);
}
foreach ($this->loadPaths as $loadPath) {
$dirs[] = $loadPath;
}
$lc->SetImportDirs($dirs);
$url = parse_url($this->getRequest()->getUriForPath(''));
$absolutePath = str_replace(public_path(), '', $root);
if (isset($url['path'])) {
$absolutePath = $url['path'] . $absolutePath;
}
$lc->parseFile($root . '/' . $path, $absolutePath);
$asset->setContent($lc->getCss());
}
示例2: filterLoad
/**
* Sets the by-config generated imports on the asset.
*
* {@inheritDoc}
*/
public function filterLoad(AssetInterface $asset)
{
$assetRoot = $asset->getSourceRoot();
$assetPath = $asset->getSourcePath();
$assetImportDir = dirname($assetRoot . '/' . $assetPath);
$importDir = $this->config->getBootstrapPath() . '/less';
$this->setupLoadPaths($assetImportDir);
// Make sure we _always_ have the bootstrap import dir.
if ($importDir !== $assetImportDir) {
$this->lessFilter->addLoadPath($importDir);
}
$variables = array_merge($this->extractVariables($importDir . '/variables.less'), $this->config->getVariables());
$variablesString = '';
foreach ($variables as $key => $value) {
$variablesString .= "@{$key}:{$value};" . PHP_EOL;
}
if ('bootstrap.less' === $assetPath) {
$imports = $this->filterImportFiles(array_unique(array_merge($this->extractImports($importDir . '/bootstrap.less'), $this->extractImports($importDir . '/responsive.less'), $this->config->getCustomComponents())));
$assetContent = $variablesString . $imports;
$asset->setContent($assetContent);
} else {
$asset->setContent($variablesString . $asset->getContent());
}
$this->lessFilter->filterLoad($asset);
}
示例3: resolveUrl
/**
* Resolves an URL from an asset.
*
* @param AssetInterface $asset the asset containing the URL
* @param string $url url read in file
*
* @return string an URL, a filepath
*/
public static function resolveUrl(AssetInterface $asset, $url)
{
// given URL is absolute URL
if (false !== strpos($url, '://')) {
return $url;
}
// source directory of the asset
$root = dirname($asset->getSourceRoot() . '/' . $asset->getTargetPath());
// path directory where asset is being copied
$path = dirname($asset->getTargetPath());
if ('.' === $path) {
$image = $url;
} else {
$image = $path . '/' . $url;
}
if (null !== $root) {
$image = $root . '/' . $url;
}
// cleanup local URLs
if (false === strpos($image, '://')) {
$image = self::removeQueryString($image);
$image = self::removeAnchor($image);
return self::resolveUps($image);
}
return $image;
}
示例4: filterDump
public function filterDump(AssetInterface $asset)
{
$content = "";
$files = array();
$extraFiles = array();
$absolutePath = $asset->getSourceRoot() . '/' . $asset->getSourcePath();
$this->parser->mime = $this->parser->mimeType($absolutePath);
if ($this->parser->mime === 'javascripts') {
$extraFiles = $this->parser->get("javascript_files", array());
}
if ($this->parser->mime === 'stylesheets') {
$extraFiles = $this->parser->get("stylesheet_files", array());
}
$absoluteFilePaths = $this->parser->getFilesArrayFromDirectives($absolutePath);
if ($absoluteFilePaths) {
$absoluteFilePaths = $extraFiles + $absoluteFilePaths;
}
foreach ($absoluteFilePaths as $absoluteFilePath) {
$files[] = $this->generator->file($absoluteFilePath, false);
}
if (!$absoluteFilePaths) {
$files[] = $this->generator->file($absolutePath, false);
}
$global_filters = $this->parser->get("sprockets_filters.{$this->parser->mime}", array());
$collection = new AssetCollection($files, $global_filters);
$asset->setContent($collection->dump());
}
示例5: filterDump
/**
* @param AssetInterface $asset
*/
public function filterDump(AssetInterface $asset)
{
$sourceBase = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$assetRoot = $this->assetRoot;
if (null === $sourcePath) {
return;
}
$content = $this->filterReferences($asset->getContent(), function ($matches) use($sourceBase, $sourcePath, $assetRoot) {
// its not a relative path
if (false !== strpos($matches['url'], '://') || 0 === strpos($matches['url'], '//') || 0 === strpos($matches['url'], 'data:') || isset($matches['url'][0]) && '/' == $matches['url'][0]) {
return $matches[0];
}
$url = $matches['url'];
if (false !== ($pos = strpos($url, '?'))) {
$url = substr($url, 0, $pos);
}
$sourceAsset = dirname($sourceBase . '/' . $sourcePath) . '/' . $url;
if (!is_file($sourceAsset)) {
return $matches[0];
}
$mimeType = MimeTypeGuesser::getInstance()->guess($sourceAsset);
$destRelativePath = substr($mimeType, 0, strpos($mimeType, '/')) . '/' . basename($url);
$destAsset = $assetRoot . '/' . $destRelativePath;
if (!is_dir(dirname($destAsset))) {
mkdir(dirname($destAsset), 0777, true);
}
copy($sourceAsset, $destAsset);
return str_replace($matches['url'], '../' . $destRelativePath, $matches[0]);
});
$asset->setContent($content);
}
示例6: doDump
/**
* Performs the asset dump.
*
* @param AssetInterface $asset An asset
* @param OutputInterface $stdout The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
private function doDump(AssetInterface $asset, OutputInterface $stdout)
{
$combinations = VarUtils::getCombinations($asset->getVars(), $this->getContainer()->getParameter('assetic.variables'));
foreach ($combinations as $combination) {
$asset->setValues($combination);
// resolve the target path
$target = rtrim($this->basePath, '/') . '/' . $asset->getTargetPath();
$target = str_replace('_controller/', '', $target);
$target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());
if (!is_dir($dir = dirname($target))) {
$stdout->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory ' . $dir);
}
}
$stdout->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
if (OutputInterface::VERBOSITY_VERBOSE <= $stdout->getVerbosity()) {
if ($asset instanceof AssetCollectionInterface) {
foreach ($asset as $leaf) {
$root = $leaf->getSourceRoot();
$path = $leaf->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
} else {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
}
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file ' . $target);
}
}
}
示例7: hashAsset
/**
* Update a given hash with the sha1 hash of an individual asset
*
* @param AssetInterface $asset
* @param $hash
*/
protected function hashAsset(AssetInterface $asset, $hash)
{
$sourcePath = $asset->getSourcePath();
$sourceRoot = $asset->getSourceRoot();
$data = $sourcePath && $sourceRoot && file_exists($sourceRoot . "/" . $sourcePath) ? hash_file('sha1', $sourceRoot . "/" . $sourcePath) : $sourcePath;
hash_update($hash, $data);
}
示例8: filterLoad
public function filterLoad(AssetInterface $asset)
{
$parser = new Less_Parser();
// CSS Rewriter will take care of this
$parser->SetOption('relativeUrls', false);
$parser->parseFile($asset->getSourceRoot() . '/' . $asset->getSourcePath());
$asset->setContent($parser->getCss());
}
示例9: filterDump
public function filterDump(AssetInterface $asset)
{
$this->root = $asset->getSourceRoot() . '/';
$this->file = $asset->getSourcePath();
$this->base = $this->getRelativePath($this->paths, $this->root);
$content = $this->filterReferences($asset->getContent(), array($this, 'url_matcher'));
$asset->setContent($content);
}
示例10: filterDump
public function filterDump(AssetInterface $asset)
{
$sourceBase = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$targetPath = $asset->getTargetPath();
if (null === $sourcePath || null === $targetPath || $sourcePath == $targetPath) {
return;
}
// learn how to get from the target back to the source
if (false !== strpos($sourceBase, '://')) {
list($scheme, $url) = explode('://', $sourceBase . '/' . $sourcePath, 2);
list($host, $path) = explode('/', $url, 2);
$host = $scheme . '://' . $host . '/';
$path = false === strpos($path, '/') ? '' : dirname($path);
$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($sourcePath)) {
$path = str_repeat('../', substr_count($targetPath, '/'));
} elseif ('.' == ($targetDir = dirname($targetPath))) {
$path = dirname($sourcePath) . '/';
} else {
while (0 !== strpos($sourcePath, $targetDir)) {
if (false !== ($pos = strrpos($targetDir, '/'))) {
$targetDir = substr($targetDir, 0, $pos);
} else {
$targetDir = '';
break;
}
}
$path = '/';
$path .= ltrim(substr(dirname($sourcePath) . '/', strlen($targetDir)), '/');
}
}
$content = $this->filterReferences($asset->getContent(), function ($matches) use($host, $path) {
if (false !== strpos($matches['url'], '://') || 0 === strpos($matches['url'], '//') || 0 === strpos($matches['url'], 'data:')) {
// absolute or protocol-relative or data uri
return $matches[0];
}
if ('/' == $matches['url'][0]) {
// root relative
return str_replace($matches['url'], $host . $matches['url'], $matches[0]);
}
// document relative
$url = $matches['url'];
$parts = array();
foreach (explode('/', $host . $path . $url) as $part) {
if ('..' === $part && count($parts) && '..' !== end($parts)) {
array_pop($parts);
}
$parts[] = $part;
}
return str_replace($matches['url'], implode('/', $parts), $matches[0]);
});
$asset->setContent($content);
}
示例11: filterLoad
public function filterLoad(AssetInterface $asset)
{
$importFilter = $this->importFilter;
$sourceRoot = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$callback = function ($matches) use($importFilter, $sourceRoot, $sourcePath) {
if (!$matches['url']) {
return $matches[0];
}
if (null === $sourceRoot) {
return $matches[0];
}
$importRoot = $sourceRoot;
if (false !== strpos($matches['url'], '://')) {
// absolute
list($importScheme, $tmp) = explode('://', $matches['url'], 2);
list($importHost, $importPath) = explode('/', $tmp, 2);
$importRoot = $importScheme . '://' . $importHost;
} elseif (0 === strpos($matches['url'], '//')) {
// protocol-relative
list($importHost, $importPath) = explode('/', substr($matches['url'], 2), 2);
$importHost = '//' . $importHost;
} elseif ('/' == $matches['url'][0]) {
// root-relative
$importPath = substr($matches['url'], 1);
} elseif (null !== $sourcePath) {
// document-relative
$importPath = $matches['url'];
if ('.' != ($sourceDir = dirname($sourcePath))) {
$importPath = $sourceDir . '/' . $importPath;
}
} else {
return $matches[0];
}
// ignore other imports
if ('css' != pathinfo($importPath, PATHINFO_EXTENSION)) {
return $matches[0];
}
$importSource = $importRoot . '/' . $importPath;
if (false !== strpos($importSource, '://') || 0 === strpos($importSource, '//')) {
$import = new HttpAsset($importSource, array($importFilter), true);
} elseif (!file_exists($importSource)) {
// ignore not found imports
return $matches[0];
} else {
$import = new FileAsset($importSource, array($importFilter), $importRoot, $importPath);
}
$import->setTargetPath($sourcePath);
return $import->dump();
};
$content = $asset->getContent();
$lastHash = md5($content);
do {
$content = $this->filterImports($content, $callback);
$hash = md5($content);
} while ($lastHash != $hash && ($lastHash = $hash));
$asset->setContent($content);
}
示例12: filterLoad
/**
* Filters an asset after it has been loaded.
*
* @param AssetInterface $asset An asset
*/
public function filterLoad(AssetInterface $asset)
{
$parser = clone $this->parser;
$parser->SetOptions($this->options);
if ($this->str_endswith($asset->getSourcePath(), ['.less'])) {
$parser->parseFile($asset->getSourceRoot() . DIRECTORY_SEPARATOR . $asset->getSourcePath());
$asset->setContent($parser->getCss());
}
}
示例13: getSourceRoot
/**
* {@inheritdoc}
*/
public function getSourceRoot()
{
if ($this->innerAsset) {
return $this->innerAsset->getSourceRoot();
}
// Not accurate, but this method is called by AssetCollectionIterator
// before setValues() is called, so we need to return something
return null;
}
示例14: filterLoad
public function filterLoad(AssetInterface $asset)
{
$options = array($this->sassPath);
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
if ($root && $path) {
$options[] = '--load-path';
$options[] = dirname($root . '/' . $path);
}
if ($this->unixNewlines) {
$options[] = '--unix-newlines';
}
if (true === $this->scss || null === $this->scss && 'scss' == pathinfo($path, PATHINFO_EXTENSION)) {
$options[] = '--scss';
}
if ($this->style) {
$options[] = '--style';
$options[] = $this->style;
}
if ($this->quiet) {
$options[] = '--quiet';
}
if ($this->debugInfo) {
$options[] = '--debug-info';
}
if ($this->lineNumbers) {
$options[] = '--line-numbers';
}
foreach ($this->loadPaths as $loadPath) {
$options[] = '--load-path';
$options[] = $loadPath;
}
if ($this->cacheLocation) {
$options[] = '--cache-location';
$options[] = $this->cacheLocation;
}
if ($this->noCache) {
$options[] = '--no-cache';
}
if ($this->compass) {
$options[] = '--compass';
}
// input
$options[] = $input = tempnam(sys_get_temp_dir(), 'assetic_sass');
file_put_contents($input, $asset->getContent());
// output
$options[] = $output = tempnam(sys_get_temp_dir(), 'assetic_sass');
$proc = new Process(implode(' ', array_map('escapeshellarg', $options)));
$code = $proc->run();
if (0 < $code) {
unlink($input);
throw new \RuntimeException($proc->getErrorOutput());
}
$asset->setContent(file_get_contents($output));
unlink($input);
unlink($output);
}
示例15: filterLoad
/**
* Filters an asset after it has been loaded.
*
* @param AssetInterface $asset An asset
*/
public function filterLoad(AssetInterface $asset)
{
if ($this->str_endswith($asset->getSourcePath(), ['.less'])) {
$file = Less_Cache::Get([$asset->getSourceRoot() . DIRECTORY_SEPARATOR . $asset->getSourcePath() => '/'], $this->options);
if (is_readable($this->options['cache_dir'] . DIRECTORY_SEPARATOR . $file)) {
$asset->setContent(file_get_contents($this->options['cache_dir'] . DIRECTORY_SEPARATOR . $file));
}
}
}