本文整理汇总了PHP中CssMin::minify方法的典型用法代码示例。如果您正苦于以下问题:PHP CssMin::minify方法的具体用法?PHP CssMin::minify怎么用?PHP CssMin::minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CssMin
的用法示例。
在下文中一共展示了CssMin::minify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
function prepare($source, $min = true)
{
if ($min) {
$source = \CssMin::minify($source);
}
return trim($source);
}
示例2: load
/**
*
*/
public function load($resource, $type = null)
{
$publishPath = $this->pathHelper->joinPaths($this->assetDirectory, $resource);
$tmpPath = $this->pathHelper->joinPaths(sys_get_temp_dir(), $resource);
$fs = $this->getFilesystem();
if ($this->debugMode) {
$fs->dumpFile($tmpPath, "/* --- composition: {$resource} ---*/");
}
$tmpFile = fopen($tmpPath, "a");
foreach ($this->compositions[$resource] as $asset) {
$path = $this->locator->locate($asset);
switch ($type) {
case 'css':
if (preg_match('/\\.min\\.css/', $asset)) {
$content = file_get_contents($path);
} else {
$content = \CssMin::minify(file_get_contents($path));
}
break;
default:
$content = file_get_contents($path);
}
if ($this->debugMode) {
fwrite($tmpFile, "\n\n/* --- asset: {$asset} ({$path}) ---*/\n\n" . $content);
}
}
fclose($tmpFile);
if ($this->publishMode && $resource !== null) {
$fs->copy($tmpPath, $publishPath);
}
return $tmpPath;
}
示例3: __invoke
public function __invoke($file, $minify = null)
{
if (!is_file($this->getOptions()->getPublicDir() . $file)) {
throw new \InvalidArgumentException('File "' . $this->getOptions()->getPublicDir() . $file . '" not found.');
}
$less = new \lessc();
$info = pathinfo($file);
$newFile = $this->getOptions()->getDestinationDir() . $info['filename'] . '.' . filemtime($this->getOptions()->getPublicDir() . $file) . '.css';
$_file = $this->getOptions()->getPublicDir() . $newFile;
if (!is_file($_file)) {
$globPattern = $this->getOptions()->getPublicDir() . $this->getOptions()->getDestinationDir() . $info['filename'] . '.*.css';
foreach (Glob::glob($globPattern, Glob::GLOB_BRACE) as $match) {
if (preg_match("/^" . $info['filename'] . "\\.[0-9]{10}\\.css\$/", basename($match))) {
unlink($match);
}
}
$compiledFile = new \SplFileObject($_file, 'w');
$result = $less->compileFile($this->getOptions()->getPublicDir() . $file);
if (is_null($minify) && $this->getOptions()->getMinify() || $minify === true) {
$result = \CssMin::minify($result);
}
$compiledFile->fwrite($result);
}
return $newFile;
}
示例4: output
/**
* Apply CssMin to $content.
*
* @param string $filename target filename
* @param string $content Content to filter.
* @throws Exception
* @return string
*/
public function output($filename, $content) {
App::import('Vendor', 'cssmin', array('file' => $this->_settings['path']));
if (!class_exists('CssMin')) {
throw new Exception(sprintf('Cannot not load filter class "%s".', 'CssMin'));
}
return CssMin::minify($content);
}
示例5: load
/**
*
*/
public function load($resource, $type = null)
{
$publishPath = $this->pathHelper->joinPaths($this->assetDirectory, $resource);
$tmpPath = $this->pathHelper->joinPaths(sys_get_temp_dir(), $resource);
$path = $this->locator->locate($resource);
$fs = $this->getFilesystem();
$fs->dumpFile($tmpPath, null);
switch ($type) {
case 'css':
// minify only if it isnt already minified
if (preg_match('/\\.min\\.css/', $resource)) {
$content = file_get_contents($path);
} else {
$content = \CssMin::minify(file_get_contents($path));
}
break;
default:
$content = file_get_contents($path);
}
file_put_contents($tmpPath, $content);
if ($this->publishMode && $resource !== null) {
$fs->copy($tmpPath, $publishPath);
}
return $tmpPath;
}
示例6: minifycss
/**
* minify css and return css link
* if minify is disabled: return direct css links
*
* @return string with html tag
* @param array $stylesheets with css files
*/
public function minifycss($stylesheets)
{
if (Zend_Registry::get('config')->cache->enable == 1 && Zend_Registry::get('config')->cache->minifycss == 1) {
// check file
$target = Zend_Registry::get('config')->pub->path . 'stylesheets/' . Zend_Registry::get('config')->cache->minifiedcssfile;
$targeturl = 'stylesheets/' . Zend_Registry::get('config')->cache->minifiedcssfile;
if (file_exists($target)) {
return "<link rel=\"stylesheet\" media=\"screen, handheld, projection, tv\" href=\"" . $targeturl . "\" />\n";
}
// load and minify files
$all = "";
foreach ($stylesheets as $css) {
$csscontent = file_get_contents(Zend_Registry::get('config')->pub->path . $css);
$csscontent = CssMin::minify($csscontent);
$all .= $csscontent;
}
file_put_contents($target, $all);
return "<link rel=\"stylesheet\" media=\"screen, handheld, projection, tv\" href=\"" . $targeturl . "\" />\n";
} else {
$ret = "";
foreach ($stylesheets as $css) {
$ret = $ret . "<link rel=\"stylesheet\" media=\"screen, handheld, projection, tv\" href=\"" . $css . "\" />\n";
}
return $ret;
}
}
示例7: apply
/**
*/
public function apply($in, $params = [])
{
require_php_lib('cssmin');
if (!class_exists('\\CssMin')) {
throw new Exception('Assets: class \\CssMin not found');
return $in;
}
return \CssMin::minify($in);
}
示例8: renderer
/**
* New resource file update handler.
*
* @param string $resource Resource full path
* @param string $extension Resource extension
* @param string $content Compiled output resource content
*/
public function renderer($resource, &$extension, &$content)
{
// If CSS resource has been updated
if ($extension === 'css') {
// Read updated CSS resource file and compile it
$content = \CssMin::minify($content);
} elseif ($extension === 'js') {
$content = \JShrink\Minifier::minify($content);
}
}
示例9: filterDump
public function filterDump(AssetInterface $asset)
{
$filters = $this->filters;
$plugins = $this->plugins;
if (isset($filters['ImportImports']) && true === $filters['ImportImports']) {
if ($dir = $asset->getSourceDirectory()) {
$filters['ImportImports'] = array('BasePath' => $dir);
} else {
unset($filters['ImportImports']);
}
}
$asset->setContent(\CssMin::minify($asset->getContent(), $filters, $plugins));
}
示例10: filterDump
public function filterDump(AssetInterface $asset)
{
$filters = $this->filters;
$plugins = $this->plugins;
if (isset($filters['ImportImports']) && true === $filters['ImportImports']) {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
if ($root && $path) {
$filters['ImportImports'] = array('BasePath' => dirname($root . '/' . $path));
} else {
unset($filters['ImportImports']);
}
}
$asset->setContent(\CssMin::minify($asset->getContent(), $filters, $plugins));
}
示例11: packer
public function packer($file, $type)
{
if (!file_exists($file)) {
return;
}
$fileDst = preg_replace('/\\.(js|css)$/', '.min.\\1', $file);
if ($type == "js") {
$minContent = JSMin::minify(file_get_contents($file));
} else {
$minContent = CssMin::minify(file_get_contents($file));
}
echo "[01;41m " . $file . " [0m -> [32;40m" . $fileDst . "[0m\n";
file_put_contents($fileDst, $minContent);
echo shell_exec("git add " . $fileDst);
}
示例12: createComponentCss
protected function createComponentCss()
{
$cssLoader = new \WebLoader\CssLoader(null, null, true);
$cssLoader->sourcePath = __DIR__ . "/css";
$cssLoader->tempUri = $this->tempUri;
$cssLoader->tempPath = $this->tempPath;
foreach ($this->css as $css) {
$cssLoader->addFile($css);
}
$cssLoader->filter();
$cssLoader->filters[] = function ($code) {
return \CssMin::minify($code);
};
return $cssLoader;
}
示例13: filterDump
public function filterDump(AssetInterface $asset)
{
$filters = $this->filters;
$plugins = $this->plugins;
if (isset($filters['ImportImports']) && true === $filters['ImportImports']) {
// find the base path
$sourceUrl = $asset->getSourceUrl();
if (self::isAbsoluteUrl($sourceUrl) || self::isAbsolutePath($sourceUrl)) {
$filters['ImportImports'] = array('BasePath' => dirname($sourceUrl));
} elseif ($this->baseDir) {
$filters['ImportImports'] = array('BasePath' => $this->baseDir);
if ('.' != ($dir = dirname($sourceUrl))) {
$filters['ImportImports']['BasePath'] .= '/' . $dir;
}
}
}
$asset->setContent(\CssMin::minify($asset->getContent(), $filters, $plugins));
}
示例14: renderCss
public function renderCss($critical = false, $type = null, $isMobile = false)
{
if ($critical) {
$this->renderCssCritical($type, $isMobile);
} else {
$config = $this->getPresenter()->context->parameters['scriptLoader']['css' . ($isMobile ? '_mobile' : '')];
if (!$this->getPresenter()->context->parameters['scriptLoader']['enable']) {
if (!is_null($config['default'])) {
foreach ($config['default'] as $css) {
echo '<link rel="stylesheet" media="screen,projection,tv" href="/' . $css . '">';
}
}
} else {
$cache = new Cache($this->getPresenter()->storage, 'scriptLoader');
if (is_null($cache->load('css' . ($isMobile ? '_mobile' : '')))) {
//zminimalizuju
$cssFile = '';
$cssFiles = array();
if (!is_null($config['default'])) {
foreach ($config['default'] as $css) {
$cssFile .= \CssMin::minify(file_get_contents($this->getPresenter()->context->parameters['wwwDir'] . '/' . $css));
$cssFiles[] = $this->getPresenter()->context->parameters['wwwDir'] . '/' . $css;
}
}
$cache->save('css' . ($isMobile ? '_mobile' : ''), true, array(Cache::FILES => $cssFiles));
file_put_contents($this->getPresenter()->context->parameters['wwwDir'] . '/css/css.css', $cssFile);
}
echo '<script>
var cb = function() {
var l = document.createElement(\'link\'); l.rel = \'stylesheet\';
l.href = \'/css/css.css\';
var h = document.getElementsByTagName(\'head\')[0]; h.parentNode.insertBefore(l, h);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else window.addEventListener(\'load\', cb);
</script>';
//echo '<link rel="stylesheet" media="screen,projection,tv" href="/css/css.css">';
}
}
}
示例15: minify
protected function minify($scripts, $ext, $output)
{
$path = $this->rootDir();
$outfile = "{$path}/{$output}";
if (file_exists($outfile)) {
if ($this->ttl == -1) {
// never recompile
return true;
}
$fileage = time() - filemtime($outfile);
if ($fileage < $this->ttl) {
return true;
}
}
$str = $this->join_files($scripts);
switch ($ext) {
case "css":
switch ($this->cssmin) {
case "cssmin":
$packed = \CssMin::minify($str);
break;
default:
$packed = $str;
}
break;
case "js":
switch ($this->jsmin) {
case "packer":
$packer = new \JavaScriptPacker($str, "Normal", true, false);
$packed = $packer->pack();
break;
case "jshrink":
$packed = \JShrink\Minifier::minify($str);
break;
default:
$packed = $str;
}
break;
}
$this->fileClient->put($outfile, $packed);
}