PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/library/Zend/View/Helper/Placeholder/Container/Standalone.php

http://digitalus-site-manager.googlecode.com/
PHP | 290 lines | 111 code | 27 blank | 152 comment | 5 complexity | 599b56c880a2778216b3bc1ff70ac65f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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. * @package Zend_View
  16. * @subpackage Helper
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: Standalone.php 10665 2008-08-05 10:57:18Z matthew $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_View_Helper_Placeholder_Registry */
  22. require_once 'Zend/View/Helper/Placeholder/Registry.php';
  23. /** Zend_View_Helper_Abstract.php */
  24. require_once 'Zend/View/Helper/Abstract.php';
  25. /**
  26. * Base class for targetted placeholder helpers
  27. *
  28. * @package Zend_View
  29. * @subpackage Helper
  30. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_View_Helper_Abstract implements IteratorAggregate, Countable, ArrayAccess
  34. {
  35. /**
  36. * @var Zend_View_Helper_Placeholder_Container_Abstract
  37. */
  38. protected $_container;
  39. /**
  40. * @var Zend_View_Helper_Placeholder_Registry
  41. */
  42. protected $_registry;
  43. /**
  44. * Registry key under which container registers itself
  45. * @var string
  46. */
  47. protected $_regKey;
  48. /**
  49. * Constructor
  50. *
  51. * @return void
  52. */
  53. public function __construct()
  54. {
  55. $this->setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry());
  56. $registry = $this->getRegistry();
  57. $this->setContainer($this->getRegistry()->getContainer($this->_regKey));
  58. }
  59. /**
  60. * Retrieve registry
  61. *
  62. * @return Zend_View_Helper_Placeholder_Registry
  63. */
  64. public function getRegistry()
  65. {
  66. return $this->_registry;
  67. }
  68. /**
  69. * Set registry object
  70. *
  71. * @param Zend_View_Helper_Placeholder_Registry $registry
  72. * @return Zend_View_Helper_Placeholder_Container_Standalone
  73. */
  74. public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry)
  75. {
  76. $this->_registry = $registry;
  77. return $this;
  78. }
  79. /**
  80. * Escape a string
  81. *
  82. * @param string $string
  83. * @return string
  84. */
  85. protected function _escape($string)
  86. {
  87. if ($this->view instanceof Zend_View_Interface) {
  88. return $this->view->escape($string);
  89. }
  90. return htmlentities((string) $string, null, 'UTF-8');
  91. }
  92. /**
  93. * Set container on which to operate
  94. *
  95. * @param Zend_View_Helper_Placeholder_Container_Abstract $container
  96. * @return Zend_View_Helper_Placeholder_Container_Standalone
  97. */
  98. public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container)
  99. {
  100. $this->_container = $container;
  101. return $this;
  102. }
  103. /**
  104. * Retrieve placeholder container
  105. *
  106. * @return Zend_View_Helper_Placeholder_Container_Abstract
  107. */
  108. public function getContainer()
  109. {
  110. return $this->_container;
  111. }
  112. /**
  113. * Overloading: set property value
  114. *
  115. * @param string $key
  116. * @param mixed $value
  117. * @return void
  118. */
  119. public function __set($key, $value)
  120. {
  121. $container = $this->getContainer();
  122. $container[$key] = $value;
  123. }
  124. /**
  125. * Overloading: retrieve property
  126. *
  127. * @param string $key
  128. * @return mixed
  129. */
  130. public function __get($key)
  131. {
  132. $container = $this->getContainer();
  133. if (isset($container[$key])) {
  134. return $container[$key];
  135. }
  136. return null;
  137. }
  138. /**
  139. * Overloading: check if property is set
  140. *
  141. * @param string $key
  142. * @return bool
  143. */
  144. public function __isset($key)
  145. {
  146. $container = $this->getContainer();
  147. return isset($container[$key]);
  148. }
  149. /**
  150. * Overloading: unset property
  151. *
  152. * @param string $key
  153. * @return void
  154. */
  155. public function __unset($key)
  156. {
  157. $container = $this->getContainer();
  158. if (isset($container[$key])) {
  159. unset($container[$key]);
  160. }
  161. }
  162. /**
  163. * Overload
  164. *
  165. * Proxy to container methods
  166. *
  167. * @param string $method
  168. * @param array $args
  169. * @return mixed
  170. */
  171. public function __call($method, $args)
  172. {
  173. $container = $this->getContainer();
  174. if (method_exists($container, $method)) {
  175. $return = call_user_func_array(array($container, $method), $args);
  176. if ($return === $container) {
  177. // If the container is returned, we really want the current object
  178. return $this;
  179. }
  180. return $return;
  181. }
  182. require_once 'Zend/View/Exception.php';
  183. throw new Zend_View_Exception('Method "' . $method . '" does not exist');
  184. }
  185. /**
  186. * String representation
  187. *
  188. * @return string
  189. */
  190. public function toString()
  191. {
  192. return $this->getContainer()->toString();
  193. }
  194. /**
  195. * Cast to string representation
  196. *
  197. * @return string
  198. */
  199. public function __toString()
  200. {
  201. return $this->toString();
  202. }
  203. /**
  204. * Countable
  205. *
  206. * @return int
  207. */
  208. public function count()
  209. {
  210. $container = $this->getContainer();
  211. return count($container);
  212. }
  213. /**
  214. * ArrayAccess: offsetExists
  215. *
  216. * @param string|int $offset
  217. * @return bool
  218. */
  219. public function offsetExists($offset)
  220. {
  221. return $this->getContainer()->offsetExists($offset);
  222. }
  223. /**
  224. * ArrayAccess: offsetGet
  225. *
  226. * @param string|int $offset
  227. * @return mixed
  228. */
  229. public function offsetGet($offset)
  230. {
  231. return $this->getContainer()->offsetGet($offset);
  232. }
  233. /**
  234. * ArrayAccess: offsetSet
  235. *
  236. * @param string|int $offset
  237. * @param mixed $value
  238. * @return void
  239. */
  240. public function offsetSet($offset, $value)
  241. {
  242. return $this->getContainer()->offsetSet($offset, $value);
  243. }
  244. /**
  245. * ArrayAccess: offsetUnset
  246. *
  247. * @param string|int $offset
  248. * @return void
  249. */
  250. public function offsetUnset($offset)
  251. {
  252. return $this->getContainer()->offsetUnset($offset);
  253. }
  254. /**
  255. * IteratorAggregate: get Iterator
  256. *
  257. * @return Iterator
  258. */
  259. public function getIterator()
  260. {
  261. return $this->getContainer()->getIterator();
  262. }
  263. }