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
Also disables the global var renaming behaviour by default
for both 1.x and 2.x (this seems like the safest choice) but
allows setSpecialVarRx(true) to enable it with the default
regex.
  • Loading branch information
AdamWill committed Jan 2, 2015
1 parent bdd814c commit 0182f4e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/Assetic/Filter/JSqueezeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,35 @@ class JSqueezeFilter implements FilterInterface
{
private $singleLine = true;
private $keepImportantComments = true;
private $specialVarRx = \JSqueeze::SPECIAL_VAR_RX;
private $className;
private $specialVarRx = false;
private $defaultRx;

function __construct() {
// JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x
if (class_exists('\\Patchwork\\JSqueeze')) {
$this->className = '\\Patchwork\\JSqueeze';
$this->defaultRx = \Patchwork\JSqueeze::SPECIAL_VAR_PACKER;
} else {
$this->className = '\\JSqueeze';
$this->defaultRx = \JSqueeze::SPECIAL_VAR_RX;
}
}

public function setSingleLine($bool)
{
$this->singleLine = (bool) $bool;
}

// call setSpecialVarRx(true) to enable global var/method/property
// renaming with the default regex (for 1.x or 2.x)
public function setSpecialVarRx($specialVarRx)
{
$this->specialVarRx = $specialVarRx;
if (true === $specialVarRx) {
$this->specialVarRx = $this->defaultRx;
} else {
$this->specialVarRx = $specialVarRx;
}
}

public function keepImportantComments($bool)
Expand All @@ -46,7 +65,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 0182f4e

Please sign in to comment.