[7575] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * This file is part of the Assetic package, an OpenSky project. |
---|
| 5 | * |
---|
| 6 | * (c) 2010-2012 OpenSky Project Inc |
---|
| 7 | * |
---|
| 8 | * For the full copyright and license information, please view the LICENSE |
---|
| 9 | * file that was distributed with this source code. |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | namespace Assetic\Asset; |
---|
| 13 | |
---|
| 14 | use Assetic\AssetManager; |
---|
| 15 | use Assetic\Filter\FilterInterface; |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * A reference to an asset in the asset manager. |
---|
| 19 | * |
---|
| 20 | * @author Kris Wallsmith <kris.wallsmith@gmail.com> |
---|
| 21 | */ |
---|
| 22 | class AssetReference implements AssetInterface |
---|
| 23 | { |
---|
| 24 | private $am; |
---|
| 25 | private $name; |
---|
| 26 | private $filters = array(); |
---|
| 27 | |
---|
| 28 | public function __construct(AssetManager $am, $name) |
---|
| 29 | { |
---|
| 30 | $this->am = $am; |
---|
| 31 | $this->name = $name; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public function ensureFilter(FilterInterface $filter) |
---|
| 35 | { |
---|
| 36 | $this->filters[] = $filter; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public function getFilters() |
---|
| 40 | { |
---|
| 41 | $this->flushFilters(); |
---|
| 42 | |
---|
| 43 | return $this->callAsset(__FUNCTION__); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public function clearFilters() |
---|
| 47 | { |
---|
| 48 | $this->filters = array(); |
---|
| 49 | $this->callAsset(__FUNCTION__); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | public function load(FilterInterface $additionalFilter = null) |
---|
| 53 | { |
---|
| 54 | $this->flushFilters(); |
---|
| 55 | |
---|
| 56 | return $this->callAsset(__FUNCTION__, array($additionalFilter)); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | public function dump(FilterInterface $additionalFilter = null) |
---|
| 60 | { |
---|
| 61 | $this->flushFilters(); |
---|
| 62 | |
---|
| 63 | return $this->callAsset(__FUNCTION__, array($additionalFilter)); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public function getContent() |
---|
| 67 | { |
---|
| 68 | return $this->callAsset(__FUNCTION__); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public function setContent($content) |
---|
| 72 | { |
---|
| 73 | $this->callAsset(__FUNCTION__, array($content)); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | public function getSourceRoot() |
---|
| 77 | { |
---|
| 78 | return $this->callAsset(__FUNCTION__); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | public function getSourcePath() |
---|
| 82 | { |
---|
| 83 | return $this->callAsset(__FUNCTION__); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | public function getTargetPath() |
---|
| 87 | { |
---|
| 88 | return $this->callAsset(__FUNCTION__); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | public function setTargetPath($targetPath) |
---|
| 92 | { |
---|
| 93 | $this->callAsset(__FUNCTION__, array($targetPath)); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | public function getLastModified() |
---|
| 97 | { |
---|
| 98 | return $this->callAsset(__FUNCTION__); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | public function getVars() |
---|
| 102 | { |
---|
| 103 | return $this->callAsset(__FUNCTION__); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | public function getValues() |
---|
| 107 | { |
---|
| 108 | return $this->callAsset(__FUNCTION__); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | public function setValues(array $values) |
---|
| 112 | { |
---|
| 113 | $this->callAsset(__FUNCTION__, array($values)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | // private |
---|
| 117 | |
---|
| 118 | private function callAsset($method, $arguments = array()) |
---|
| 119 | { |
---|
| 120 | $asset = $this->am->get($this->name); |
---|
| 121 | |
---|
| 122 | return call_user_func_array(array($asset, $method), $arguments); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | private function flushFilters() |
---|
| 126 | { |
---|
| 127 | $asset = $this->am->get($this->name); |
---|
| 128 | |
---|
| 129 | while ($filter = array_shift($this->filters)) { |
---|
| 130 | $asset->ensureFilter($filter); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|