|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_View |
|
17 * @subpackage Helper |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @version $Id: Standalone.php 20143 2010-01-08 15:17:11Z matthew $ |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 */ |
|
22 |
|
23 /** Zend_View_Helper_Placeholder_Registry */ |
|
24 require_once 'Zend/View/Helper/Placeholder/Registry.php'; |
|
25 |
|
26 /** Zend_View_Helper_Abstract.php */ |
|
27 require_once 'Zend/View/Helper/Abstract.php'; |
|
28 |
|
29 /** |
|
30 * Base class for targetted placeholder helpers |
|
31 * |
|
32 * @package Zend_View |
|
33 * @subpackage Helper |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_View_Helper_Abstract implements IteratorAggregate, Countable, ArrayAccess |
|
38 { |
|
39 /** |
|
40 * @var Zend_View_Helper_Placeholder_Container_Abstract |
|
41 */ |
|
42 protected $_container; |
|
43 |
|
44 /** |
|
45 * @var Zend_View_Helper_Placeholder_Registry |
|
46 */ |
|
47 protected $_registry; |
|
48 |
|
49 /** |
|
50 * Registry key under which container registers itself |
|
51 * @var string |
|
52 */ |
|
53 protected $_regKey; |
|
54 |
|
55 /** |
|
56 * Flag wheter to automatically escape output, must also be |
|
57 * enforced in the child class if __toString/toString is overriden |
|
58 * @var book |
|
59 */ |
|
60 protected $_autoEscape = true; |
|
61 |
|
62 /** |
|
63 * Constructor |
|
64 * |
|
65 * @return void |
|
66 */ |
|
67 public function __construct() |
|
68 { |
|
69 $this->setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry()); |
|
70 $this->setContainer($this->getRegistry()->getContainer($this->_regKey)); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Retrieve registry |
|
75 * |
|
76 * @return Zend_View_Helper_Placeholder_Registry |
|
77 */ |
|
78 public function getRegistry() |
|
79 { |
|
80 return $this->_registry; |
|
81 } |
|
82 |
|
83 /** |
|
84 * Set registry object |
|
85 * |
|
86 * @param Zend_View_Helper_Placeholder_Registry $registry |
|
87 * @return Zend_View_Helper_Placeholder_Container_Standalone |
|
88 */ |
|
89 public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry) |
|
90 { |
|
91 $this->_registry = $registry; |
|
92 return $this; |
|
93 } |
|
94 |
|
95 /** |
|
96 * Set whether or not auto escaping should be used |
|
97 * |
|
98 * @param bool $autoEscape whether or not to auto escape output |
|
99 * @return Zend_View_Helper_Placeholder_Container_Standalone |
|
100 */ |
|
101 public function setAutoEscape($autoEscape = true) |
|
102 { |
|
103 $this->_autoEscape = ($autoEscape) ? true : false; |
|
104 return $this; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Return whether autoEscaping is enabled or disabled |
|
109 * |
|
110 * return bool |
|
111 */ |
|
112 public function getAutoEscape() |
|
113 { |
|
114 return $this->_autoEscape; |
|
115 } |
|
116 |
|
117 /** |
|
118 * Escape a string |
|
119 * |
|
120 * @param string $string |
|
121 * @return string |
|
122 */ |
|
123 protected function _escape($string) |
|
124 { |
|
125 $enc = 'UTF-8'; |
|
126 if ($this->view instanceof Zend_View_Interface |
|
127 && method_exists($this->view, 'getEncoding') |
|
128 ) { |
|
129 $enc = $this->view->getEncoding(); |
|
130 } |
|
131 |
|
132 return htmlspecialchars((string) $string, ENT_COMPAT, $enc); |
|
133 } |
|
134 |
|
135 /** |
|
136 * Set container on which to operate |
|
137 * |
|
138 * @param Zend_View_Helper_Placeholder_Container_Abstract $container |
|
139 * @return Zend_View_Helper_Placeholder_Container_Standalone |
|
140 */ |
|
141 public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container) |
|
142 { |
|
143 $this->_container = $container; |
|
144 return $this; |
|
145 } |
|
146 |
|
147 /** |
|
148 * Retrieve placeholder container |
|
149 * |
|
150 * @return Zend_View_Helper_Placeholder_Container_Abstract |
|
151 */ |
|
152 public function getContainer() |
|
153 { |
|
154 return $this->_container; |
|
155 } |
|
156 |
|
157 /** |
|
158 * Overloading: set property value |
|
159 * |
|
160 * @param string $key |
|
161 * @param mixed $value |
|
162 * @return void |
|
163 */ |
|
164 public function __set($key, $value) |
|
165 { |
|
166 $container = $this->getContainer(); |
|
167 $container[$key] = $value; |
|
168 } |
|
169 |
|
170 /** |
|
171 * Overloading: retrieve property |
|
172 * |
|
173 * @param string $key |
|
174 * @return mixed |
|
175 */ |
|
176 public function __get($key) |
|
177 { |
|
178 $container = $this->getContainer(); |
|
179 if (isset($container[$key])) { |
|
180 return $container[$key]; |
|
181 } |
|
182 |
|
183 return null; |
|
184 } |
|
185 |
|
186 /** |
|
187 * Overloading: check if property is set |
|
188 * |
|
189 * @param string $key |
|
190 * @return bool |
|
191 */ |
|
192 public function __isset($key) |
|
193 { |
|
194 $container = $this->getContainer(); |
|
195 return isset($container[$key]); |
|
196 } |
|
197 |
|
198 /** |
|
199 * Overloading: unset property |
|
200 * |
|
201 * @param string $key |
|
202 * @return void |
|
203 */ |
|
204 public function __unset($key) |
|
205 { |
|
206 $container = $this->getContainer(); |
|
207 if (isset($container[$key])) { |
|
208 unset($container[$key]); |
|
209 } |
|
210 } |
|
211 |
|
212 /** |
|
213 * Overload |
|
214 * |
|
215 * Proxy to container methods |
|
216 * |
|
217 * @param string $method |
|
218 * @param array $args |
|
219 * @return mixed |
|
220 */ |
|
221 public function __call($method, $args) |
|
222 { |
|
223 $container = $this->getContainer(); |
|
224 if (method_exists($container, $method)) { |
|
225 $return = call_user_func_array(array($container, $method), $args); |
|
226 if ($return === $container) { |
|
227 // If the container is returned, we really want the current object |
|
228 return $this; |
|
229 } |
|
230 return $return; |
|
231 } |
|
232 |
|
233 require_once 'Zend/View/Exception.php'; |
|
234 $e = new Zend_View_Exception('Method "' . $method . '" does not exist'); |
|
235 $e->setView($this->view); |
|
236 throw $e; |
|
237 } |
|
238 |
|
239 /** |
|
240 * String representation |
|
241 * |
|
242 * @return string |
|
243 */ |
|
244 public function toString() |
|
245 { |
|
246 return $this->getContainer()->toString(); |
|
247 } |
|
248 |
|
249 /** |
|
250 * Cast to string representation |
|
251 * |
|
252 * @return string |
|
253 */ |
|
254 public function __toString() |
|
255 { |
|
256 return $this->toString(); |
|
257 } |
|
258 |
|
259 /** |
|
260 * Countable |
|
261 * |
|
262 * @return int |
|
263 */ |
|
264 public function count() |
|
265 { |
|
266 $container = $this->getContainer(); |
|
267 return count($container); |
|
268 } |
|
269 |
|
270 /** |
|
271 * ArrayAccess: offsetExists |
|
272 * |
|
273 * @param string|int $offset |
|
274 * @return bool |
|
275 */ |
|
276 public function offsetExists($offset) |
|
277 { |
|
278 return $this->getContainer()->offsetExists($offset); |
|
279 } |
|
280 |
|
281 /** |
|
282 * ArrayAccess: offsetGet |
|
283 * |
|
284 * @param string|int $offset |
|
285 * @return mixed |
|
286 */ |
|
287 public function offsetGet($offset) |
|
288 { |
|
289 return $this->getContainer()->offsetGet($offset); |
|
290 } |
|
291 |
|
292 /** |
|
293 * ArrayAccess: offsetSet |
|
294 * |
|
295 * @param string|int $offset |
|
296 * @param mixed $value |
|
297 * @return void |
|
298 */ |
|
299 public function offsetSet($offset, $value) |
|
300 { |
|
301 return $this->getContainer()->offsetSet($offset, $value); |
|
302 } |
|
303 |
|
304 /** |
|
305 * ArrayAccess: offsetUnset |
|
306 * |
|
307 * @param string|int $offset |
|
308 * @return void |
|
309 */ |
|
310 public function offsetUnset($offset) |
|
311 { |
|
312 return $this->getContainer()->offsetUnset($offset); |
|
313 } |
|
314 |
|
315 /** |
|
316 * IteratorAggregate: get Iterator |
|
317 * |
|
318 * @return Iterator |
|
319 */ |
|
320 public function getIterator() |
|
321 { |
|
322 return $this->getContainer()->getIterator(); |
|
323 } |
|
324 } |