Skip to content

Commit

Permalink
Make JSqueeze filter work with 1.x and 2.x (namespaced)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWill committed Jan 1, 2015
1 parent bdd814c commit 4854406
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Assetic/Filter/JSqueezeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ class JSqueezeFilter implements FilterInterface
{
private $singleLine = true;
private $keepImportantComments = true;
private $specialVarRx = \JSqueeze::SPECIAL_VAR_RX;
private $classname;
private $specialVarRx;

function __construct() {
// JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x
// Upstream default for special var is false in 2.x
if (class_exists('\\Patchwork\\JSqueeze')) {
$this->classname = '\\Patchwork\\JSqueeze';
$this->specialVarRx = false;
} else {
$this->classname = '\\JSqueeze';
$this->specialVarRx = $this->classname::SPECIAL_VAR_RX;
}
}

public function setSingleLine($bool)
{
Expand All @@ -46,7 +59,7 @@ public function filterLoad(AssetInterface $asset)

public function filterDump(AssetInterface $asset)
{
$parser = new \JSqueeze();
$parser = new $this->classname();
$asset->setContent($parser->squeeze(
$asset->getContent(),
$this->singleLine,
Expand Down

0 comments on commit 4854406

Please sign in to comment.