Created
January 11, 2012 18:48
-
-
Save swvitaliy/1596143 to your computer and use it in GitHub Desktop.
Simple yui js|css compressor php wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* yuicompressor.php | |
* Simple wrapper for yui js|css compressor | |
* | |
* Author: swvitaliy | |
*/ | |
class yuicompressor { | |
const COMMAND = 'java -jar {path_to_jar}yuicompressor-{version}.jar --type={type} {output_file} {input_file}'; | |
public static $path_to_jar; | |
public static $version = '2.4.2'; | |
protected static function compileCommand ($custom = array()) | |
{ | |
$config = array ( | |
'path_to_jar'=>self::$path_to_jar, | |
'version'=>self::$version, | |
); | |
$str = self::COMMAND; | |
foreach (array_merge($config, $custom) as $k=>$v) | |
$str = str_replace('{'.$k.'}',$v,$str); | |
return $str; | |
} | |
public static function minify ($type, $input_file, $output_file = NULL) | |
{ | |
$options = array('type'=>$type, 'input_file' => $input_file); | |
$options ['output_file'] = ($output_file !== NULL) ? '-o ' . $output_file : ''; | |
$text = passthru(self::compileCommand($options)); | |
if (!$options['output_file']) | |
return $text; | |
return TRUE; | |
} | |
} | |
// yuicompressor::$path_to_jar = __DIR__ . '/'; | |
// echo yuicompressor::minify('css', '/full/path/to/cssfile.css'); | |
// echo yuicompressor::minify('js', '/full/path/to/jsfile.js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment