AssetReference.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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\Asset;
  11. use Assetic\AssetManager;
  12. use Assetic\Filter\FilterCollection;
  13. use Assetic\Filter\FilterInterface;
  14. /**
  15. * A reference to an asset in the asset manager.
  16. *
  17. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  18. */
  19. class AssetReference implements AssetInterface
  20. {
  21. private $am;
  22. private $name;
  23. private $filters = array();
  24. public function __construct(AssetManager $am, $name)
  25. {
  26. $this->am = $am;
  27. $this->name = $name;
  28. }
  29. public function ensureFilter(FilterInterface $filter)
  30. {
  31. $this->filters[] = $filter;
  32. }
  33. public function getFilters()
  34. {
  35. $this->flushFilters();
  36. return $this->callAsset(__FUNCTION__);
  37. }
  38. public function clearFilters()
  39. {
  40. $this->filters = array();
  41. $this->callAsset(__FUNCTION__);
  42. }
  43. public function load(FilterInterface $additionalFilter = null)
  44. {
  45. $this->flushFilters();
  46. return $this->callAsset(__FUNCTION__, array($additionalFilter));
  47. }
  48. public function dump(FilterInterface $additionalFilter = null)
  49. {
  50. $this->flushFilters();
  51. return $this->callAsset(__FUNCTION__, array($additionalFilter));
  52. }
  53. public function getContent()
  54. {
  55. return $this->callAsset(__FUNCTION__);
  56. }
  57. public function setContent($content)
  58. {
  59. $this->callAsset(__FUNCTION__, array($content));
  60. }
  61. public function getSourceRoot()
  62. {
  63. return $this->callAsset(__FUNCTION__);
  64. }
  65. public function getSourcePath()
  66. {
  67. return $this->callAsset(__FUNCTION__);
  68. }
  69. public function getTargetPath()
  70. {
  71. return $this->callAsset(__FUNCTION__);
  72. }
  73. public function setTargetPath($targetPath)
  74. {
  75. $this->callAsset(__FUNCTION__, array($targetPath));
  76. }
  77. public function getLastModified()
  78. {
  79. return $this->callAsset(__FUNCTION__);
  80. }
  81. // private
  82. private function callAsset($method, $arguments = array())
  83. {
  84. $asset = $this->am->get($this->name);
  85. return call_user_func_array(array($asset, $method), $arguments);
  86. }
  87. private function flushFilters()
  88. {
  89. $asset = $this->am->get($this->name);
  90. while ($filter = array_shift($this->filters)) {
  91. $asset->ensureFilter($filter);
  92. }
  93. }
  94. }