Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in Dean Edwards' JavaScript Packer
- Loading branch information
Showing
2 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Munee: Optimising Your Assets | ||
* | ||
* @copyright Cody Lundquist 2013 | ||
* @license http://opensource.org/licenses/mit-license.php | ||
*/ | ||
|
||
namespace Munee\Asset\Filter\JavaScript; | ||
|
||
use Munee\Asset\Filter; | ||
use \JavaScriptPacker; | ||
|
||
/** | ||
* Dean Edwards' Packer Filter for JavaScript | ||
* | ||
* @author Cody Lundquist | ||
*/ | ||
class Packer extends Filter | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $_allowedParams = array( | ||
'packer' => array( | ||
'regex' => 'true|false|t|f|yes|no|y|n', | ||
'default' => 'false', | ||
'cast' => 'boolean' | ||
) | ||
); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_defaultOptions = array( | ||
'encoding' => 62, | ||
'fastDecode' => true, | ||
'specialChars' => false | ||
); | ||
|
||
/** | ||
* JavaScript Packer | ||
* | ||
* @param string $file | ||
* @param array $arguments | ||
* @param array $javaScriptOptions | ||
* | ||
* @return void | ||
*/ | ||
public function doFilter($file, $arguments, $javaScriptOptions) | ||
{ | ||
$userOptions = isset($javaScriptOptions['packer']) ? $javaScriptOptions['packer'] : array(); | ||
$options = array_merge($this->_defaultOptions, $userOptions); | ||
|
||
if (! $arguments['packer']) { | ||
return; | ||
} | ||
|
||
$content = file_get_contents($file); | ||
$packer = new JavaScriptPacker($content, $options['encoding'], $options['fastDecode'], $options['specialChars']); | ||
file_put_contents($file, $packer->pack()); | ||
} | ||
} |