Fuel Compressor
Now, I have started using FuelPHP, which is an awesome new PHP 5.3 framework! It’s been the framework for the new gfxtub, and it’s really working out quite well. Since starting using fuel, I have contributed an Image and Email class, and now I made my first package: Fuel Compressor.
Really how it works is simple. The compressor works like the asset class, sort of. An example of using the compressor is:
Fuel::add_package('compressor');
$files = array('script1.js', 'script2.js', 'scriptN.js');
// Echos <script src="http://.../scripts.pack.js" type="text/javascript"></script>
echo Compressor::js($files, 'scripts.pack');
Now, that’s a basic example of taking multiple scripts, compressing, and adding them to you assets folder. Note that it can cache to folders other than the assets folder (Set in ‘compressor/config/compressor.php’), but it will force the use of a js and css folder within the configured folder. This behavior is because the package was designed as a simple way of auto-magically compressing your scripts while you work on them locally, then not have to worry about it in the production environment.
It will return the code if the 2nd param is null:
$myscript = "Script goes here";
$myjs = Compressor::js($myscript);
echo $myjs; // Echos the compressed js
$myscripts = array('scripts.js');
$myjs = Compressor::js($myscripts);
echo $myjs; // Echos the compressed js files
That about covers the basic use. There is a HTML compressor, but it’s just a basic call to the html-compressor lib. Also, the documentation in the actually classes folder should cover anything not said here.