当前位置: 首页>>代码示例>>PHP>>正文


PHP FileAsset::setContent方法代码示例

本文整理汇总了PHP中Assetic\Asset\FileAsset::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP FileAsset::setContent方法的具体用法?PHP FileAsset::setContent怎么用?PHP FileAsset::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assetic\Asset\FileAsset的用法示例。


在下文中一共展示了FileAsset::setContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: asset

 /**
  * @param $path String target path
  * @return \Assetic\Filter\FileAsset
  */
 public function asset($opts = array())
 {
     $asset = new FileAsset($this->real_path);
     $ext = strtolower(substr($this->real_path, strrpos($this->real_path, '.')));
     if (in_array($ext, array('.css', '.scss'))) {
         //il faut rajouter la méthode asset-url
         $scss = new ScssphpFilter();
         if (isset($opts['compass']) && $opts['compass']) {
             $scss->enableCompass(true);
         }
         $scss->registerFunction('aphet_url', function ($args, $scss) {
             if ($args[0][0] === 'string') {
                 $url = is_array($args[0][2][0]) ? $args[0][2][0][2][0] : $args[0][2][0];
             } else {
                 throw new \Exception('je ne sais pas quoi faire là');
             }
             if (strpos($url, '?') !== false) {
                 list($url, $query) = explode('?', $url);
             } else {
                 $query = null;
             }
             if (strpos($url, '#') !== false) {
                 list($url, $hash) = explode('#', $url);
             } else {
                 $hash = null;
             }
             return 'url(' . aphet_url($url) . ($query ? "?{$query}" : '') . ($hash ? "?{$hash}" : '') . ')';
         });
         $asset->ensureFilter($scss);
     } elseif ($ext === '.js') {
         $filter = new \Assetic\Filter\CallablesFilter(function ($asset) {
             $asset->setContent(preg_replace_callback('/aphet_url\\((.*)\\)/', function ($match) {
                 return '\'' . aphet_url(json_decode($match[1])) . '\'';
             }, $asset->getContent()));
         });
         $asset->ensureFilter($filter);
     }
     return $asset;
 }
开发者ID:lalop,项目名称:aphet,代码行数:43,代码来源:File.php

示例2: filterDump

 public function filterDump(AssetInterface $asset)
 {
     $sourceBase = $asset->getSourceRoot();
     $sourcePath = $asset->getSourcePath();
     $targetPath = $asset->getTargetPath();
     $sourceDir = $asset->getSourceDirectory();
     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 {
             $path = '';
             while (0 !== strpos($sourcePath, $targetDir)) {
                 if (false !== ($pos = strrpos($targetDir, '/'))) {
                     $targetDir = substr($targetDir, 0, $pos);
                     $path .= '../';
                 } else {
                     $targetDir = '';
                     $path .= '../';
                     break;
                 }
             }
             $path .= ltrim(substr(dirname($sourcePath) . '/', strlen($targetDir)), '/');
         }
     }
     $content = $this->filterReferences($asset->getContent(), function ($matches) use($sourceDir, $host) {
         $path = $sourceDir;
         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 (isset($matches['url'][0]) && '/' == $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);
         }
         $originalAsset = $path . $url;
         $originalAsset = reset(preg_split("/[#?]/", $originalAsset));
         $rootDir = $this->kernel->getRootDir();
         $rootDir = substr($rootDir, 0, -3);
         $relativeAsset = substr($originalAsset, strlen($rootDir));
         $assetName = $this->assetFactory->generateAssetName($relativeAsset);
         $targetAssetPath = $rootDir . 'web/' . $url;
         $targetParts = explode('/', $targetAssetPath);
         $fileName = $assetName . '_' . array_pop($targetParts);
         array_push($targetParts, $fileName);
         $targetAssetPath = implode('/', $targetParts);
         $targetAssetPath = reset(preg_split("/[#?]/", $targetAssetPath));
         $urlParts = explode('/', $matches['url']);
         array_pop($urlParts);
         array_push($urlParts, $fileName);
         $urlNew = implode('/', $urlParts);
         if (!is_dir($dir = dirname($targetAssetPath))) {
             if (false === @mkdir($dir, 0777, true)) {
                 throw new \RuntimeException('Unable to create directory ' . $dir);
             }
         }
         $asset = new FileAsset($originalAsset);
         try {
             $contents = $asset->dump();
         } catch (\Exception $e) {
             echo 'WARNING: ' . $e->getMessage();
         }
         if (false === @file_put_contents($targetAssetPath, $contents)) {
             throw new \RuntimeException('Unable to write file ' . $targetAssetPath);
         }
         $result = str_replace($matches['url'], $urlNew, $matches[0]);
         return $result;
     });
     $asset->setContent($content);
 }
开发者ID:henrypenny,项目名称:hmp-assetic-bundle,代码行数:90,代码来源:CssDumpFilter.php


注:本文中的Assetic\Asset\FileAsset::setContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。