1 | <?php |
||
19 | class Template_Layers extends Priority |
||
20 | { |
||
21 | /** |
||
22 | * Layers not removed in case of errors |
||
23 | */ |
||
24 | private $_error_safe_layers = null; |
||
25 | |||
26 | /** |
||
27 | * Are we handling an error? |
||
28 | * Hopefully not, so default is false |
||
29 | */ |
||
30 | private $_is_error = false; |
||
31 | |||
32 | /** |
||
33 | * The layers added when this is true will be used in the error screen |
||
34 | */ |
||
35 | private static $_error_safe = false; |
||
36 | |||
37 | /** |
||
38 | * Instance of the class |
||
39 | */ |
||
40 | private static $_instance = null; |
||
41 | |||
42 | /** |
||
43 | * Add a new layer to the pile |
||
44 | * |
||
45 | * @param string $layer name of a layer |
||
46 | * @param int|null $priority an integer defining the priority of the layer. |
||
47 | */ |
||
48 | 8 | public function add($layer, $priority = null) |
|
49 | { |
||
50 | 8 | parent::add($layer, $priority); |
|
51 | |||
52 | 8 | if (self::$_error_safe) |
|
53 | 8 | $this->_error_safe_layers[] = $layer; |
|
54 | 8 | } |
|
55 | |||
56 | /** |
||
57 | * Add a layer to the pile before another existing layer |
||
58 | * |
||
59 | * @param string $layer the name of a layer |
||
60 | * @param string $following the name of the layer before which $layer must be added |
||
61 | */ |
||
62 | public function addBefore($layer, $following) |
||
69 | |||
70 | /** |
||
71 | * Add a layer to the pile after another existing layer |
||
72 | * |
||
73 | * @param string $layer the name of a layer |
||
74 | * @param string $previous the name of the layer after which $layer must be added |
||
75 | */ |
||
76 | public function addAfter($layer, $previous) |
||
83 | |||
84 | /** |
||
85 | * Add a layer at the end of the pile |
||
86 | * |
||
87 | * @param string $layer name of a layer |
||
88 | * @param int|null $priority an integer defining the priority of the layer. |
||
89 | */ |
||
90 | public function addEnd($layer, $priority = null) |
||
97 | |||
98 | /** |
||
99 | * Add a layer at the beginning of the pile |
||
100 | * |
||
101 | * @param string $layer name of a layer |
||
102 | * @param int|null $priority an integer defining the priority of the layer. |
||
103 | */ |
||
104 | 7 | public function addBegin($layer, $priority = null) |
|
111 | |||
112 | /** |
||
113 | * Prepares the layers so that they are usable by the template |
||
114 | * The function sorts the layers according to the priority and saves the |
||
115 | * result in $_sorted_entities |
||
116 | * |
||
117 | * @return array the sorted layers |
||
118 | */ |
||
119 | public function prepareContext() |
||
141 | |||
142 | /** |
||
143 | * Reverse the layers order |
||
144 | * |
||
145 | * @return array the reverse ordered layers |
||
146 | */ |
||
147 | public function reverseLayers() |
||
154 | |||
155 | /** |
||
156 | * Check if at least one layer has been added |
||
157 | * |
||
158 | * @param boolean $base if true will not consider body and html layers in result |
||
159 | * @return bool true if at least one layer has been added |
||
160 | * @todo at that moment _all_after and _all_before are not considered because they may not be "forced" |
||
161 | */ |
||
162 | public function hasLayers($base = false) |
||
169 | |||
170 | /** |
||
171 | * Return the layers that have been loaded |
||
172 | */ |
||
173 | public function getLayers() |
||
177 | |||
178 | /** |
||
179 | * Turns "error mode" on, so that only the allowed layers are displayed |
||
180 | */ |
||
181 | public function isError() |
||
185 | |||
186 | /** |
||
187 | * Find and return Template_Layers instance if it exists, |
||
188 | * or create a new instance if it didn't already exist. |
||
189 | * |
||
190 | * @param boolean $error_safe if error mode is on or off |
||
191 | * @return Template_Layers instance of the class |
||
192 | */ |
||
193 | 13 | public static function instance($error_safe = false) |
|
202 | |||
203 | /** |
||
204 | * Find and return Template_Layers instance if it exists, |
||
205 | * or create a new instance if it didn't already exist. |
||
206 | * |
||
207 | * @deprecated since Elk 1.1 - use instance instead |
||
208 | * |
||
209 | * @param boolean $error_safe if error mode is on or off |
||
210 | * @return Template_Layers instance of the class |
||
211 | */ |
||
212 | public static function getInstance($error_safe = false) |
||
216 | } |
||
217 |