1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * This file is part of the Assetic package, an OpenSky project. |
---|
5 | * |
---|
6 | * (c) 2010-2012 OpenSky Project Inc |
---|
7 | * |
---|
8 | * For the full copyright and license information, please view the LICENSE |
---|
9 | * file that was distributed with this source code. |
---|
10 | */ |
---|
11 | |
---|
12 | namespace Assetic\Filter\Yui; |
---|
13 | |
---|
14 | use Assetic\Asset\AssetInterface; |
---|
15 | |
---|
16 | /** |
---|
17 | * Javascript YUI compressor filter. |
---|
18 | * |
---|
19 | * @link http://developer.yahoo.com/yui/compressor/ |
---|
20 | * @author Kris Wallsmith <kris.wallsmith@gmail.com> |
---|
21 | */ |
---|
22 | class JsCompressorFilter extends BaseCompressorFilter |
---|
23 | { |
---|
24 | private $nomunge; |
---|
25 | private $preserveSemi; |
---|
26 | private $disableOptimizations; |
---|
27 | |
---|
28 | public function setNomunge($nomunge = true) |
---|
29 | { |
---|
30 | $this->nomunge = $nomunge; |
---|
31 | } |
---|
32 | |
---|
33 | public function setPreserveSemi($preserveSemi) |
---|
34 | { |
---|
35 | $this->preserveSemi = $preserveSemi; |
---|
36 | } |
---|
37 | |
---|
38 | public function setDisableOptimizations($disableOptimizations) |
---|
39 | { |
---|
40 | $this->disableOptimizations = $disableOptimizations; |
---|
41 | } |
---|
42 | |
---|
43 | public function filterDump(AssetInterface $asset) |
---|
44 | { |
---|
45 | $options = array(); |
---|
46 | |
---|
47 | if ($this->nomunge) { |
---|
48 | $options[] = '--nomunge'; |
---|
49 | } |
---|
50 | |
---|
51 | if ($this->preserveSemi) { |
---|
52 | $options[] = '--preserve-semi'; |
---|
53 | } |
---|
54 | |
---|
55 | if ($this->disableOptimizations) { |
---|
56 | $options[] = '--disable-optimizations'; |
---|
57 | } |
---|
58 | |
---|
59 | $asset->setContent($this->compress($asset->getContent(), 'js', $options)); |
---|
60 | } |
---|
61 | } |
---|