JsCompressorFilter.php 1.3KB

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