PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/clearhealth/clearhealth
PHP | 319 lines | 121 code | 30 blank | 168 comment | 5 complexity | d4ba307c0eeae77d4bf168cdcb36cfa4 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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 11373 2008-09-12 17:00:05Z ralph $
  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. * Flag wheter to automatically escape output, must also be
  50. * enforced in the child class if __toString/toString is overriden
  51. * @var book
  52. */
  53. protected $_autoEscape = true;
  54. /**
  55. * Constructor
  56. *
  57. * @return void
  58. */
  59. public function __construct()
  60. {
  61. $this->setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry());
  62. $registry = $this->getRegistry();
  63. $this->setContainer($this->getRegistry()->getContainer($this->_regKey));
  64. }
  65. /**
  66. * Retrieve registry
  67. *
  68. * @return Zend_View_Helper_Placeholder_Registry
  69. */
  70. public function getRegistry()
  71. {
  72. return $this->_registry;
  73. }
  74. /**
  75. * Set registry object
  76. *
  77. * @param Zend_View_Helper_Placeholder_Registry $registry
  78. * @return Zend_View_Helper_Placeholder_Container_Standalone
  79. */
  80. public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry)
  81. {
  82. $this->_registry = $registry;
  83. return $this;
  84. }
  85. /**
  86. * Set whether or not auto escaping should be used
  87. *
  88. * @param bool $autoEscape whether or not to auto escape output
  89. * @return Zend_View_Helper_Placeholder_Container_Standalone
  90. */
  91. public function setAutoEscape($autoEscape = true)
  92. {
  93. $this->_autoEscape = ($autoEscape) ? true : false;
  94. return $this;
  95. }
  96. /**
  97. * Return whether autoEscaping is enabled or disabled
  98. *
  99. * return bool
  100. */
  101. public function getAutoEscape()
  102. {
  103. return $this->_autoEscape;
  104. }
  105. /**
  106. * Escape a string
  107. *
  108. * @param string $string
  109. * @return string
  110. */
  111. protected function _escape($string)
  112. {
  113. if ($this->view instanceof Zend_View_Interface) {
  114. return $this->view->escape($string);
  115. }
  116. return htmlentities((string) $string, null, 'UTF-8');
  117. }
  118. /**
  119. * Set container on which to operate
  120. *
  121. * @param Zend_View_Helper_Placeholder_Container_Abstract $container
  122. * @return Zend_View_Helper_Placeholder_Container_Standalone
  123. */
  124. public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container)
  125. {
  126. $this->_container = $container;
  127. return $this;
  128. }
  129. /**
  130. * Retrieve placeholder container
  131. *
  132. * @return Zend_View_Helper_Placeholder_Container_Abstract
  133. */
  134. public function getContainer()
  135. {
  136. return $this->_container;
  137. }
  138. /**
  139. * Overloading: set property value
  140. *
  141. * @param string $key
  142. * @param mixed $value
  143. * @return void
  144. */
  145. public function __set($key, $value)
  146. {
  147. $container = $this->getContainer();
  148. $container[$key] = $value;
  149. }
  150. /**
  151. * Overloading: retrieve property
  152. *
  153. * @param string $key
  154. * @return mixed
  155. */
  156. public function __get($key)
  157. {
  158. $container = $this->getContainer();
  159. if (isset($container[$key])) {
  160. return $container[$key];
  161. }
  162. return null;
  163. }
  164. /**
  165. * Overloading: check if property is set
  166. *
  167. * @param string $key
  168. * @return bool
  169. */
  170. public function __isset($key)
  171. {
  172. $container = $this->getContainer();
  173. return isset($container[$key]);
  174. }
  175. /**
  176. * Overloading: unset property
  177. *
  178. * @param string $key
  179. * @return void
  180. */
  181. public function __unset($key)
  182. {
  183. $container = $this->getContainer();
  184. if (isset($container[$key])) {
  185. unset($container[$key]);
  186. }
  187. }
  188. /**
  189. * Overload
  190. *
  191. * Proxy to container methods
  192. *
  193. * @param string $method
  194. * @param array $args
  195. * @return mixed
  196. */
  197. public function __call($method, $args)
  198. {
  199. $container = $this->getContainer();
  200. if (method_exists($container, $method)) {
  201. $return = call_user_func_array(array($container, $method), $args);
  202. if ($return === $container) {
  203. // If the container is returned, we really want the current object
  204. return $this;
  205. }
  206. return $return;
  207. }
  208. require_once 'Zend/View/Exception.php';
  209. throw new Zend_View_Exception('Method "' . $method . '" does not exist');
  210. }
  211. /**
  212. * String representation
  213. *
  214. * @return string
  215. */
  216. public function toString()
  217. {
  218. return $this->getContainer()->toString();
  219. }
  220. /**
  221. * Cast to string representation
  222. *
  223. * @return string
  224. */
  225. public function __toString()
  226. {
  227. return $this->toString();
  228. }
  229. /**
  230. * Countable
  231. *
  232. * @return int
  233. */
  234. public function count()
  235. {
  236. $container = $this->getContainer();
  237. return count($container);
  238. }
  239. /**
  240. * ArrayAccess: offsetExists
  241. *
  242. * @param string|int $offset
  243. * @return bool
  244. */
  245. public function offsetExists($offset)
  246. {
  247. return $this->getContainer()->offsetExists($offset);
  248. }
  249. /**
  250. * ArrayAccess: offsetGet
  251. *
  252. * @param string|int $offset
  253. * @return mixed
  254. */
  255. public function offsetGet($offset)
  256. {
  257. return $this->getContainer()->offsetGet($offset);
  258. }
  259. /**
  260. * ArrayAccess: offsetSet
  261. *
  262. * @param string|int $offset
  263. * @param mixed $value
  264. * @return void
  265. */
  266. public function offsetSet($offset, $value)
  267. {
  268. return $this->getContainer()->offsetSet($offset, $value);
  269. }
  270. /**
  271. * ArrayAccess: offsetUnset
  272. *
  273. * @param string|int $offset
  274. * @return void
  275. */
  276. public function offsetUnset($offset)
  277. {
  278. return $this->getContainer()->offsetUnset($offset);
  279. }
  280. /**
  281. * IteratorAggregate: get Iterator
  282. *
  283. * @return Iterator
  284. */
  285. public function getIterator()
  286. {
  287. return $this->getContainer()->getIterator();
  288. }
  289. }