當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。