AsseticFilterInvoker.php 1.3KB

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