Пример #1
0
 public function compressJs($march)
 {
     return str_replace($march['1'], compressJs($march['1']), $march['0']);
 }
Пример #2
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";