Example #1
0
 public function compressCss($match)
 {
     return '<style type = "text/css">' . compressCss($match['1']) . '</style>';
 }
Example #2
0
/**
 * @param   string      $file
 * @param   string      $min
 * @return  string|boolean
 */
function getCss($file, $mode = 'min')
{
    $file = (is_dir('css') ? '.' : '..') . '/css/' . $file;
    $css = is_file($file) || is_file($file .= '.css') ? file_get_contents($file) : false;
    return $css && 'min' === $mode ? compressCss($css) : $css;
}
Example #3
0
}
@unlink('tracy.phar');
// @ - file may not exist
$phar = new Phar('tracy.phar');
$phar->setStub("<?php\nrequire 'phar://' . __FILE__ . '/tracy.php';\n__HALT_COMPILER();\n");
$phar->startBuffering();
foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../../src', RecursiveDirectoryIterator::SKIP_DOTS)) as $file) {
    echo "adding: {$iterator->getSubPathname()}\n";
    $s = php_strip_whitespace($file);
    if ($file->getExtension() === 'js') {
        $s = compressJs($s);
    } elseif ($file->getExtension() === 'css') {
        $s = compressCss($s);
    } elseif ($file->getExtension() === 'phtml') {
        $s = preg_replace_callback('#(<(script|style).*(?<![?=])>)(.*)(</)#Uis', function ($m) {
            list(, $begin, $type, $s, $end) = $m;
            if ($s === '' || strpos($s, '<?') !== FALSE) {
                return $m[0];
            } elseif ($type === 'script') {
                $s = compressJs($s);
            } elseif ($type === 'style') {
                $s = compressCss($s);
            }
            return $begin . $s . $end;
        }, $s);
    }
    $phar[$iterator->getSubPathname()] = $s;
}
$phar->stopBuffering();
$phar->compressFiles(Phar::GZ);
echo "OK\n";