CssMinFilter.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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;
  11. use Assetic\Asset\AssetInterface;
  12. /**
  13. * Filters assets through CssMin.
  14. *
  15. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  16. */
  17. class CssMinFilter implements FilterInterface
  18. {
  19. private $filters;
  20. private $plugins;
  21. public function __construct()
  22. {
  23. $this->filters = array();
  24. $this->plugins = array();
  25. }
  26. public function setFilters(array $filters)
  27. {
  28. $this->filters = $filters;
  29. }
  30. public function setFilter($name, $value)
  31. {
  32. $this->filters[$name] = $value;
  33. }
  34. public function setPlugins(array $plugins)
  35. {
  36. $this->plugins = $plugins;
  37. }
  38. public function setPlugin($name, $value)
  39. {
  40. $this->plugins[$name] = $value;
  41. }
  42. public function filterLoad(AssetInterface $asset)
  43. {
  44. }
  45. public function filterDump(AssetInterface $asset)
  46. {
  47. $filters = $this->filters;
  48. $plugins = $this->plugins;
  49. if (isset($filters['ImportImports']) && true === $filters['ImportImports']) {
  50. $root = $asset->getSourceRoot();
  51. $path = $asset->getSourcePath();
  52. if ($root && $path) {
  53. $filters['ImportImports'] = array('BasePath' => dirname($root.'/'.$path));
  54. } else {
  55. unset($filters['ImportImports']);
  56. }
  57. }
  58. $asset->setContent(\CssMin::minify($asset->getContent(), $filters, $plugins));
  59. }
  60. }