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


PHP FileAsset::dump方法代码示例

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


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

示例1: fonts

 public function fonts(array $params)
 {
     $font = $params['font'];
     if (strlen($font) < 1) {
         return false;
     }
     $fontfiles = Registry::getInstance()->assets['fonts'];
     if (isset($fontfiles[$font])) {
         $asset = new FileAsset($fontfiles[$font]);
         switch (strtolower(substr($font, strpos($font, ".")))) {
             case ".eot":
                 $type = "application/vnd.ms-fontobject";
                 break;
             case "otf":
                 $type = "font/opentype";
                 break;
             case "ttf":
                 $type = "application/x-font-ttf";
                 break;
             case ".woff":
                 $type = "application/x-font-woff";
                 break;
             default:
                 $type = "application/x-font";
         }
         header('Content-Type: ' . $type);
         echo $asset->dump();
     }
     return true;
 }
开发者ID:kingboard,项目名称:kingboard,代码行数:30,代码来源:Assetic.php

示例2: onTerminate

 public function onTerminate(CarewEvent $carewEvent)
 {
     foreach ($this->finder->in($carewEvent->getArgument('webDir')) as $file) {
         $asset = new FileAsset($file->getPathname(), array($this->getFilter()));
         file_put_contents($file->getPathname(), $asset->dump());
     }
 }
开发者ID:francisbesset,项目名称:carew-assetic,代码行数:7,代码来源:AbstractListener.php

示例3: 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);
 }
开发者ID:laiello,项目名称:mediathequescrum,代码行数:58,代码来源:CssImportFilter.php

示例4: background

 public function background(array $params)
 {
     $backgrounds = Registry::getInstance()->assets['backgrounds'];
     $dt = new \DateTime();
     $dt->setTime(date("H"), 0, 0);
     srand($dt->getTimestamp());
     $asset = new \Assetic\Asset\FileAsset($backgrounds[rand(0, count($backgrounds) - 1)]);
     header('Content-Type: image/jpeg');
     header("Cache-Control: public, max-age=3600, s-max-age=1800");
     echo $asset->dump();
     return true;
 }
开发者ID:kingboard,项目名称:kingboard,代码行数:12,代码来源:Assetic.php

示例5: testImport

    /**
     * @dataProvider getFilters
     */
    public function testImport($filter1, $filter2)
    {
        $asset = new FileAsset(__DIR__ . '/fixtures/cssimport/main.css', array(), __DIR__ . '/fixtures/cssimport', 'main.css');
        $asset->setTargetPath('foo/bar.css');
        $asset->ensureFilter($filter1);
        $asset->ensureFilter($filter2);
        $expected = <<<CSS
/* main.css */
/* import.css */
body { color: red; }
/* more/evenmore/deep1.css */
/* more/evenmore/deep2.css */
body {
    background: url(../more/evenmore/bg.gif);
}
body { color: black; }
CSS;
        $this->assertEquals($expected, $asset->dump(), '->filterLoad() inlines CSS imports');
    }
开发者ID:alexanderTsig,项目名称:arabic,代码行数:22,代码来源:CssImportFilterTest.php

示例6: indexAction

 /**
  * Integrator brand stylesheet.
  *
  * @Route("/style")
  * @Method({"GET"})
  *
  * @param Request $request
  * @return Response
  */
 public function indexAction(Request $request)
 {
     // Get vendor key
     $vendorKey = $this->getVendorCredentials()['vendorKey'];
     $d = DIRECTORY_SEPARATOR;
     // Get the system web directory
     $sysDir = $this->container->get('kernel')->getRootdir() . "{$d}..{$d}web{$d}";
     // Get the style sheet input path to the uncompiled (raw from IRIS) vendor CSS file
     $sysPathUncompiled = "{$sysDir}css{$d}integrator{$d}uncompiled{$d}{$vendorKey}.less";
     // Get the style sheet output path to the compiled (post Assetic) vendor CSS file
     $sysPathCompiled = "{$sysDir}css{$d}integrator{$d}compiled{$d}{$vendorKey}.css";
     $compiledCss = '';
     // Does a compiled CSS file exist for it that is also under x seconds old?
     if (!file_exists($sysPathCompiled) || $this->httpCacheMaxAgeInSeconds < filemtime($sysPathCompiled)) {
         // No CSS file exists or it's stale, make a new one
         // Get vendor style config, import the main style into it, and store it to disc in the uncompiled directory
         $vendorStyle = $this->getVendorStyle();
         $vendorStyle .= "\n\n@import '../style.less';";
         // todo Make better
         file_put_contents($sysPathUncompiled, $vendorStyle);
         /** @var CssRewriteFilter $asseticFilterCssRewrite */
         $asseticFilterCssRewrite = $this->container->get('assetic.filter.cssrewrite');
         /** @var LessphpFilter $asseticFilterLessPhp */
         $asseticFilterLessPhp = $this->container->get('assetic.filter.lessphp');
         $asseticFilterLessPhp->setFormatter('classic');
         $asseticFilterLessPhp->setPreserveComments(false);
         $style = new FileAsset($sysPathUncompiled, array($asseticFilterCssRewrite, $asseticFilterLessPhp));
         // Dump compiled CSS to file
         $compiledCss = $style->dump();
         file_put_contents($sysPathCompiled, $compiledCss);
     } else {
         // Grab compiled CSS from file
         $compiledCss = file_get_contents($sysPathCompiled);
     }
     // Output compiled CSS
     $this->response->headers->set('Content-Type', 'text/css');
     $this->response->setContent($compiledCss);
     return $this->response;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:48,代码来源:StyleController.php

示例7: listen

 /**
  * @param RequestResponseEvent $event
  */
 public function listen(RequestResponseEvent $event)
 {
     $path = $event->getRequest()->getPathInfo();
     $parts = pathinfo($path);
     $parts = array_merge(array('dirname' => '', 'basename' => '', 'extension' => '', 'filename'), $parts);
     switch (strtolower($parts['extension'])) {
         case 'css':
             //possible it's not yet compiled less file?
             $lessFile = $this->container->getApplication()->getWebRoot() . $path . '.less';
             if (is_file($lessFile)) {
                 $asset = new FileAsset($lessFile);
                 $asset->ensureFilter(new LessphpFilter());
                 $content = $this->container->getCache()->fetch('assets_404', $path, function () use($asset) {
                     return $asset->dump();
                 }, $asset->getLastModified(), 0, true);
                 $event->setResponse(new Response($content, 200, array('Content-Type' => 'text/css')));
                 $event->stopPropagation();
                 return;
             }
             break;
     }
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:25,代码来源:NotFoundAssetExceptionListener.php

示例8: mergeAssetCssJsFile

 /**
  * 合并文件,并且返回合并之后的文件名
  *
  * @param  string  $moduleUniqueId
  * @param array    $fileRelativePathArray
  * @param string   $fileExt                     合并之后的文件扩展名
  * @param callback $fileContentFilter           对每个文件的内容做 filter
  *
  * @return string 合并之后的文件名
  */
 private function mergeAssetCssJsFile($moduleUniqueId, array $fileRelativePathArray, $fileExt, $fileContentFilter = null)
 {
     if (empty($fileRelativePathArray)) {
         throw new \InvalidArgumentException('fileRelativePathArray can not be empty');
     }
     $targetModuleBasePath = $this->assetBasePath . DIRECTORY_SEPARATOR . $this->getModulePublishRelativeDir($moduleUniqueId) . DIRECTORY_SEPARATOR;
     // 计算合并之后的文件名
     $targetFileNameSource = '';
     foreach ($fileRelativePathArray as $relativeAssetPath) {
         // 智能发布资源
         $this->publishAsset($moduleUniqueId, $relativeAssetPath);
         $sourcePath = $targetModuleBasePath . $relativeAssetPath;
         if (!is_file($sourcePath)) {
             printLog('Calculate FileNameSource Error : [' . $sourcePath . '] is not a regular file', 'AssetManager', \Core\Log\Base::ERROR);
             continue;
         }
         $targetModifyTime = filemtime($sourcePath);
         $targetFileNameSource .= '{' . $sourcePath . '[' . $targetModifyTime . ']}';
     }
     // 目标文件名
     $targetFileNameSourceMd5 = md5($targetFileNameSource);
     $targetFileName = $targetFileNameSourceMd5 . '.min' . $fileExt;
     // 合并文件已经存在,直接退出就可以了
     if (is_file($targetModuleBasePath . $targetFileName)) {
         goto out;
     }
     // 打印 log
     printLog($targetFileNameSource, 'AssetManager');
     // 做文件的合并
     $filterArray = array();
     // 建立对应的 filter
     if ('.js' == $fileExt) {
         $filterArray = array(new JSMinFilter());
     } elseif ('.css' == $fileExt) {
         $filterArray = array(new CssImportFilter(), new CssRewriteFilter(), new CssMinFilter());
     } else {
         // do nothing
     }
     $mergeFileContent = '';
     foreach ($fileRelativePathArray as $relativeAssetPath) {
         $sourcePath = $targetModuleBasePath . $relativeAssetPath;
         if (!is_file($sourcePath)) {
             printLog('Merge File Error : [' . $sourcePath . '] is not a regular file', 'AssetManager', \Core\Log\Base::ERROR);
             continue;
         }
         // 我们采用 Assetic 来做文件处理
         $fileAsset = new FileAsset($targetModuleBasePath . $relativeAssetPath, $filterArray, $targetModuleBasePath, $relativeAssetPath);
         $fileAsset->setTargetPath('.');
         $mergeFileContent .= $fileContentFilter ? call_user_func_array($fileContentFilter, array($relativeAssetPath, $fileAsset->dump())) : $fileAsset->dump();
         unset($fileAsset);
         // 释放内存
     }
     // 生成合并之后的文件
     file_put_contents($targetModuleBasePath . $targetFileName, $mergeFileContent);
     out:
     return $targetFileName;
 }
开发者ID:swcug,项目名称:bzfshop,代码行数:67,代码来源:SimpleManager.php

示例9: testNotFindModuleNameAmongPaths

 /**
  * When first part of a module name is not specified in paths and not equals baseUrl, we can't find module
  * so this module exclusions will not be excluded
  *
  * @covers Hearsay\RequireJSBundle\Assetic\Filter\RJsFilter::filterDump
  * @covers Hearsay\RequireJSBundle\Assetic\Filter\RJsFilter::addModule
  * @covers Hearsay\RequireJSBundle\Assetic\Filter\RJsFilter::addOption
  */
 public function testNotFindModuleNameAmongPaths()
 {
     $this->filter->addOption('preserveLicenseComments', false);
     // registering optimizer modules config
     $this->filter->addModule("module/file3", array("include" => array("module/file", "module/file2")));
     $this->filter->addModule("module2/file4", array("exclude" => array("module/file3")));
     $asset = new FileAsset(__DIR__ . '/modules/module2/file4.js');
     $asset->ensureFilter($this->filter);
     // expecting result contains only content of file4 although file4 depends on file3 and file3 depends on file 2 and file
     $this->assertRegExp('/^define\\("module\\/file2",\\{js:"got it twice"\\}\\),define\\("module\\/file",\\{js:"got it"\\}\\),' . 'require\\(\\["module\\/file2","module\\/file"\\],function\\(e,t\\)\\{return console.log\\(e,t\\)\\}\\),' . 'define\\("module\\/file3",function\\(\\)\\{\\}\\),require\\(\\["module\\/file3"\\],function\\(e\\)\\{return console.log\\(e\\)\\}\\),' . 'define\\(".{32}",function\\(\\)\\{\\}\\);$/', $asset->dump(), 'Defined exclusions for modules/module2/file4.js excluded incorrectly');
 }
开发者ID:boskee,项目名称:HearsayRequireJSBundle,代码行数:19,代码来源:RJsFilterTest.php

示例10: 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

示例11: hookGetPageLayout

    /**
     * Add yaml css to layout.
     *
     * @param Database_Result $objPage
     * @param Database_Result $objLayout
     * @param PageRegular $objPageRegular
     */
    public function hookGetPageLayout($objPage, $objLayout, $objPageRegular)
    {
        $autoInclude = $objLayout->xyaml_auto_include || $GLOBALS['TL_CONFIG']['yaml_auto_include'];
        $path = $objLayout->xyaml_auto_include ? $objLayout->xyaml_path : $GLOBALS['TL_CONFIG']['yaml_path'];
        if ($autoInclude && $objLayout->xyaml && !empty($path)) {
            $mode = $objLayout->xyaml_auto_include ? $objLayout->xyaml_mode : $GLOBALS['TL_CONFIG']['yaml_mode'];
            $filter = $objLayout->xyaml_auto_include ? $objLayout->xyaml_compass_filter : $GLOBALS['TL_CONFIG']['yaml_compass_filter'];
            $path = \Compat::resolveFile($path, false);
            if ($path) {
                if (!is_array($GLOBALS['TL_CSS'])) {
                    $GLOBALS['TL_CSS'] = array();
                }
                if (!is_array($GLOBALS['TL_JAVASCRIPT'])) {
                    $GLOBALS['TL_JAVASCRIPT'] = array();
                }
                $useSass = $mode == 'sass';
                if ($useSass) {
                    $activeModules = \Config::getInstance()->getActiveModules();
                    if (!in_array('assetic', $activeModules)) {
                        throw new \RuntimeException('Cannot use YAML SASS without assetic extension');
                    }
                    global $container;
                    /** @var AsseticFactory $factory */
                    $factory = $container['assetic.factory'];
                    $filters = array($factory->createFilterOrChain($filter));
                } else {
                    $filters = array();
                }
                // add yaml addons
                $addons = deserialize($objLayout->xyaml_addons, true);
                $this->addFiles($objPage, $objLayout, $addons, $GLOBALS['YAML_ADDONS'], $path, $useSass, $filters);
                // add yaml forms
                $forms = deserialize($objLayout->xyaml_forms, true);
                $this->addFiles($objPage, $objLayout, $forms, $GLOBALS['YAML_FORMS'], $path, $useSass, $filters);
                // add yaml navigation
                $navigations = deserialize($objLayout->xyaml_navigation, true);
                $this->addFiles($objPage, $objLayout, $navigations, $GLOBALS['YAML_NAVIGATION'], $path, $useSass, $filters);
                // add yaml print
                $prints = deserialize($objLayout->xyaml_print, true);
                $this->addFiles($objPage, $objLayout, $prints, $GLOBALS['YAML_PRINT'], $path, $useSass, $filters);
                // add yaml screen
                $screens = deserialize($objLayout->xyaml_screen, true);
                $this->addFiles($objPage, $objLayout, $screens, $GLOBALS['YAML_SCREEN'], $path, $useSass, $filters);
                // add yaml base
                $this->addStyleSheets($objPage, $objLayout, array('core/base.css'), $path, $useSass, $filters);
                // add yaml iehacks
                if ($objLayout->xyaml_iehacks) {
                    $ieHacks = $path . '/core/iehacks.min.css';
                    if ($useSass) {
                        $targetPath = 'assets/css/iehacks-' . substr(md5($path), 0, 8) . '.css';
                        if (!file_exists(TL_ROOT . '/' . $targetPath)) {
                            // load asset
                            $asset = new FileAsset(TL_ROOT . '/' . $path . '/core/_iehacks.scss', $filters, TL_ROOT, $path . '/core/_iehacks.scss');
                            $asset->setTargetPath(TL_ROOT . '/' . $targetPath);
                            $asset->dump();
                        }
                        $ieHacks = $targetPath;
                    }
                    $GLOBALS['TL_HEAD']['xyaml_iehacks'] = <<<EOF
<!--[if lte IE 7]>
<link rel="stylesheet" href="{$ieHacks}" type="text/css"/>
<![endif]-->
EOF;
                }
                // linearize level
                if ($objLayout->xyaml_subcolumns_linearize) {
                    $cssClass = ' linearize-level-' . $objLayout->xyaml_subcolumns_linearize;
                    $GLOBALS['TL_SUBCL']['yaml4']['scclass'] .= $cssClass;
                    $GLOBALS['TL_SUBCL']['yaml4_additional']['scclass'] .= $cssClass;
                }
            }
        }
        return false;
    }
开发者ID:bit3,项目名称:contao-xyaml,代码行数:81,代码来源:Hooks.php


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