ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
AssetReference.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2014 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
12namespace Assetic\Asset;
13
16
23{
24 private $am;
25 private $name;
26 private $filters = array();
27 private $clone = false;
28 private $asset;
29
31 {
32 $this->am = $am;
33 $this->name = $name;
34 }
35
36 public function __clone()
37 {
38 $this->clone = true;
39
40 if ($this->asset) {
41 $this->asset = clone $this->asset;
42 }
43 }
44
45 public function ensureFilter(FilterInterface $filter)
46 {
47 $this->filters[] = $filter;
48 }
49
50 public function getFilters()
51 {
52 $this->flushFilters();
53
54 return $this->callAsset(__FUNCTION__);
55 }
56
57 public function clearFilters()
58 {
59 $this->filters = array();
60 $this->callAsset(__FUNCTION__);
61 }
62
63 public function load(FilterInterface $additionalFilter = null)
64 {
65 $this->flushFilters();
66
67 return $this->callAsset(__FUNCTION__, array($additionalFilter));
68 }
69
70 public function dump(FilterInterface $additionalFilter = null)
71 {
72 $this->flushFilters();
73
74 return $this->callAsset(__FUNCTION__, array($additionalFilter));
75 }
76
77 public function getContent()
78 {
79 return $this->callAsset(__FUNCTION__);
80 }
81
82 public function setContent($content)
83 {
84 $this->callAsset(__FUNCTION__, array($content));
85 }
86
87 public function getSourceRoot()
88 {
89 return $this->callAsset(__FUNCTION__);
90 }
91
92 public function getSourcePath()
93 {
94 return $this->callAsset(__FUNCTION__);
95 }
96
97 public function getSourceDirectory()
98 {
99 return $this->callAsset(__FUNCTION__);
100 }
101
102 public function getTargetPath()
103 {
104 return $this->callAsset(__FUNCTION__);
105 }
106
107 public function setTargetPath($targetPath)
108 {
109 $this->callAsset(__FUNCTION__, array($targetPath));
110 }
111
112 public function getLastModified()
113 {
114 return $this->callAsset(__FUNCTION__);
115 }
116
117 public function getVars()
118 {
119 return $this->callAsset(__FUNCTION__);
120 }
121
122 public function getValues()
123 {
124 return $this->callAsset(__FUNCTION__);
125 }
126
127 public function setValues(array $values)
128 {
129 $this->callAsset(__FUNCTION__, array($values));
130 }
131
132 // private
133
134 private function callAsset($method, $arguments = array())
135 {
136 $asset = $this->resolve();
137
138 return call_user_func_array(array($asset, $method), $arguments);
139 }
140
141 private function flushFilters()
142 {
143 $asset = $this->resolve();
144
145 while ($filter = array_shift($this->filters)) {
146 $asset->ensureFilter($filter);
147 }
148 }
149
150 private function resolve()
151 {
152 if ($this->asset) {
153 return $this->asset;
154 }
155
156 $asset = $this->am->get($this->name);
157
158 if ($this->clone) {
159 $asset = $this->asset = clone $asset;
160 }
161
162 return $asset;
163 }
164}
Manages assets.
A reference to an asset in the asset manager.
ensureFilter(FilterInterface $filter)
Ensures the current asset includes the supplied filter.
getTargetPath()
Returns the URL for the current asset.
setValues(array $values)
Sets the values for the asset's variables.
setContent($content)
Sets the content of the current asset.
callAsset($method, $arguments=array())
dump(FilterInterface $additionalFilter=null)
Applies dump filters and returns the asset as a string.
getSourceRoot()
Returns an absolute path or URL to the source asset's root directory.
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
getContent()
Returns the loaded content of the current asset.
getFilters()
Returns an array of filters currently applied.
getSourcePath()
Returns the relative path for the source asset.
clearFilters()
Clears all filters from the current asset.
getVars()
Returns an array of variable names for this asset.
getValues()
Returns the current values for this asset.
getSourceDirectory()
Returns the asset's source directory.
__construct(AssetManager $am, $name)
getLastModified()
Returns the time the current asset was last modified.
setTargetPath($targetPath)
Sets the URL for the current asset.
An exception for terminatinating execution or to throw for unit testing.
An asset has a mutable URL and content and can be loaded and dumped.
A filter manipulates an asset at load and dump.