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


PHP CssMin::run方法代码示例

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


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

示例1: minifyCss

 public static function minifyCss($cssList, $concat = false)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website');
     $cacheHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('cache');
     if (null === ($hashStack = $cacheHelper->load(strtolower(__CLASS__), ''))) {
         $hashStack = array();
     }
     $container = $cssList->getContainer();
     foreach ($container->getArrayCopy() as $css) {
         if (preg_match('/^https?:\\/\\//', $css->href) != false && strpos($css->href, $websiteHelper->getUrl()) !== 0) {
             continue;
         }
         $path = str_replace($websiteHelper->getUrl(), '', $css->href);
         if (!is_file($websiteHelper->getPath() . $path) || !file_exists($websiteHelper->getPath() . $path)) {
             continue;
         }
         $hash = sha1_file($websiteHelper->getPath() . $path);
         $name = Tools_Filesystem_Tools::basename($path);
         if (!$hash) {
             continue;
         }
         if (!isset($hashStack[$path]) || $hashStack[$path]['hash'] !== $hash) {
             $compressor = new CssMin();
             $cssContent = Tools_Filesystem_Tools::getFile($path);
             $cssContent = preg_replace('/url\\([\'"]?([^)\'"]*)[\'"]?\\)/', 'url("../' . dirname($path) . DIRECTORY_SEPARATOR . '${1}")', $cssContent);
             $hashStack[$path] = array('hash' => $hash, 'content' => $compressor->run($cssContent));
             Tools_Filesystem_Tools::saveFile($websiteHelper->getPath() . $websiteHelper->getTmp() . $hash . '.css', $hashStack[$path]['content']);
             unset($cssContent);
         }
         if (!$concat) {
             $css->href = $websiteHelper->getUrl() . $websiteHelper->getTmp() . $hash . '.css?' . $name;
         } else {
             $concatCss = isset($concatCss) ? $concatCss . PHP_EOL . "/* {$path} */" . PHP_EOL . $hashStack[$path]['content'] : "/* {$path} */" . PHP_EOL . $hashStack[$path]['content'];
         }
     }
     if (isset($concatCss) && !empty($concatCss)) {
         $cname = sha1($concatCss) . '.concat.min.css';
         $concatPath = $websiteHelper->getPath() . $websiteHelper->getTmp() . $cname;
         if (!file_exists($concatPath) || sha1_file($concatPath) !== sha1($concatCss)) {
             Tools_Filesystem_Tools::saveFile($concatPath, $concatCss);
         }
         $cssList->setStylesheet($websiteHelper->getUrl() . $websiteHelper->getTmp() . $cname);
     }
     $cacheHelper->save(strtolower(__CLASS__), $hashStack, '', array(), Helpers_Action_Cache::CACHE_LONG);
     return $cssList;
 }
开发者ID:PavloKovalov,项目名称:seotoaster,代码行数:46,代码来源:Minify.php

示例2: _getContent

 private function _getContent()
 {
     $content = '';
     $compressor = new CssMin();
     foreach ($this->_getFilesCss() as $file) {
         if (!file_exists($this->_themeFullPath . $file)) {
             continue;
         }
         $fileName = explode('/', $this->_themeFullPath . $file);
         $fileName = strtoupper(end($fileName));
         $content .= "/**** " . $fileName . " start ****/\n";
         $content .= $compressor->run(preg_replace('~\\@charset\\s\\"utf-8\\"\\;~Ui', '', file_get_contents($this->_themeFullPath . $file)));
         $content .= "\n/**** " . $fileName . " end ****/\n";
     }
     return $content;
 }
开发者ID:PavloKovalov,项目名称:seotoaster,代码行数:16,代码来源:Concatcss.php


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