4
* This file is part of the Assetic package, an OpenSky project.
6
* (c) 2010-2013 OpenSky Project Inc
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
12
namespace Assetic\Filter;
14
use Assetic\Asset\AssetInterface;
15
use Assetic\Exception\FilterException;
18
* Filter for the Google Closure Stylesheets Compiler JAR.
20
* @link http://code.google.com/p/closure-stylesheets/
21
* @author Matthias Krauser <matthias@krauser.eu>
23
class GssFilter extends BaseProcessFilter
27
private $allowUnrecognizedFunctions;
28
private $allowedNonStandardFunctions;
29
private $copyrightNotice;
31
private $gssFunctionMapProvider;
32
private $inputOrientation;
33
private $outputOrientation;
36
public function __construct($jarPath, $javaPath = '/usr/bin/java')
38
$this->jarPath = $jarPath;
39
$this->javaPath = $javaPath;
42
public function setAllowUnrecognizedFunctions($allowUnrecognizedFunctions)
44
$this->allowUnrecognizedFunctions = $allowUnrecognizedFunctions;
47
public function setAllowedNonStandardFunctions($allowNonStandardFunctions)
49
$this->allowedNonStandardFunctions = $allowNonStandardFunctions;
52
public function setCopyrightNotice($copyrightNotice)
54
$this->copyrightNotice = $copyrightNotice;
57
public function setDefine($define)
59
$this->define = $define;
62
public function setGssFunctionMapProvider($gssFunctionMapProvider)
64
$this->gssFunctionMapProvider = $gssFunctionMapProvider;
67
public function setInputOrientation($inputOrientation)
69
$this->inputOrientation = $inputOrientation;
72
public function setOutputOrientation($outputOrientation)
74
$this->outputOrientation = $outputOrientation;
77
public function setPrettyPrint($prettyPrint)
79
$this->prettyPrint = $prettyPrint;
82
public function filterLoad(AssetInterface $asset)
86
$pb = $this->createProcessBuilder(array(
92
if (null !== $this->allowUnrecognizedFunctions) {
93
$pb->add('--allow-unrecognized-functions');
96
if (null !== $this->allowedNonStandardFunctions) {
97
$pb->add('--allowed_non_standard_functions')->add($this->allowedNonStandardFunctions);
100
if (null !== $this->copyrightNotice) {
101
$pb->add('--copyright-notice')->add($this->copyrightNotice);
104
if (null !== $this->define) {
105
$pb->add('--define')->add($this->define);
108
if (null !== $this->gssFunctionMapProvider) {
109
$pb->add('--gss-function-map-provider')->add($this->gssFunctionMapProvider);
112
if (null !== $this->inputOrientation) {
113
$pb->add('--input-orientation')->add($this->inputOrientation);
116
if (null !== $this->outputOrientation) {
117
$pb->add('--output-orientation')->add($this->outputOrientation);
120
if (null !== $this->prettyPrint) {
121
$pb->add('--pretty-print');
124
$pb->add($cleanup[] = $input = tempnam(sys_get_temp_dir(), 'assetic_google_closure_stylesheets_compiler'));
125
file_put_contents($input, $asset->getContent());
127
$proc = $pb->getProcess();
128
$code = $proc->run();
129
array_map('unlink', $cleanup);
132
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
135
$asset->setContent($proc->getOutput());
138
public function filterDump(AssetInterface $asset)