本文整理汇总了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;
}
示例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;
}