AsseticFilterInvoker.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 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\Extension\Twig;
  11. use Assetic\Factory\AssetFactory;
  12. /**
  13. * Filters a single asset.
  14. *
  15. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  16. */
  17. class AsseticFilterInvoker
  18. {
  19. private $factory;
  20. private $filters;
  21. private $options;
  22. public function __construct($factory, $filter)
  23. {
  24. $this->factory = $factory;
  25. if (is_array($filter) && isset($filter['filter'])) {
  26. $this->filters = (array) $filter['filter'];
  27. $this->options = isset($filter['options']) ? (array) $filter['options'] : array();
  28. } else {
  29. $this->filters = (array) $filter;
  30. $this->options = array();
  31. }
  32. }
  33. public function getFactory()
  34. {
  35. return $this->factory;
  36. }
  37. public function getFilters()
  38. {
  39. return $this->filters;
  40. }
  41. public function getOptions()
  42. {
  43. return $this->options;
  44. }
  45. public function invoke($input, array $options = array())
  46. {
  47. $asset = $this->factory->createAsset($input, $this->filters, $options + $this->options);
  48. return $asset->getTargetPath();
  49. }
  50. }