Source of file AbstractStandalone.php
Size: 8,387 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/View/Helper/Placeholder/Container/AbstractStandalone.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\View\Helper\Placeholder\Container; use ArrayAccess; use Countable; use IteratorAggregate; use Zend\Escaper\Escaper; use Zend\View\Exception; use Zend\View\Helper\AbstractHelper; use Zend\View\Renderer\RendererInterface; /** * Base class for targeted placeholder helpers */ abstract class AbstractStandalone extends AbstractHelper implements IteratorAggregate, Countable, ArrayAccess { /** * Flag whether to automatically escape output, must also be * enforced in the child class if __toString/toString is overridden * * @var bool */ protected $autoEscape = true; /** * @var AbstractContainer */ protected $container; /** * Default container class * @var string */ protected $containerClass = 'Zend\View\Helper\Placeholder\Container'; /** * @var Escaper[] */ protected $escapers = array(); /** * Constructor * */ public function __construct() { $this->setContainer($this->getContainer()); } /** * Overload * * Proxy to container methods * * @param string $method * @param array $args * @throws Exception\BadMethodCallException * @return mixed */ public function __call($method, $args) { $container = $this->getContainer(); if (method_exists($container, $method)) { $return = call_user_func_array(array($container, $method), $args); if ($return === $container) { // If the container is returned, we really want the current object return $this; } return $return; } throw new Exception\BadMethodCallException('Method "' . $method . '" does not exist'); } /** * Overloading: set property value * * @param string $key * @param mixed $value * @return void */ public function __set($key, $value) { $container = $this->getContainer(); $container[$key] = $value; } /** * Overloading: retrieve property * * @param string $key * @return mixed */ public function __get($key) { $container = $this->getContainer(); if (isset($container[$key])) { return $container[$key]; } return null; } /** * Overloading: check if property is set * * @param string $key * @return bool */ public function __isset($key) { $container = $this->getContainer(); return isset($container[$key]); } /** * Overloading: unset property * * @param string $key * @return void */ public function __unset($key) { $container = $this->getContainer(); if (isset($container[$key])) { unset($container[$key]); } } /** * Cast to string representation * * @return string */ public function __toString() { return $this->toString(); } /** * String representation * * @return string */ public function toString() { return $this->getContainer()->toString(); } /** * Escape a string * * @param string $string * @return string */ protected function escape($string) { if ($this->getView() instanceof RendererInterface && method_exists($this->getView(), 'getEncoding') ) { $escaper = $this->getView()->plugin('escapeHtml'); return $escaper((string) $string); } return $this->getEscaper()->escapeHtml((string) $string); } /** * Set whether or not auto escaping should be used * * @param bool $autoEscape whether or not to auto escape output * @return AbstractStandalone */ public function setAutoEscape($autoEscape = true) { $this->autoEscape = ($autoEscape) ? true : false; return $this; } /** * Return whether autoEscaping is enabled or disabled * * return bool */ public function getAutoEscape() { return $this->autoEscape; } /** * Set container on which to operate * * @param AbstractContainer $container * @return AbstractStandalone */ public function setContainer(AbstractContainer $container) { $this->container = $container; return $this; } /** * Retrieve placeholder container * * @return AbstractContainer */ public function getContainer() { if (!$this->container instanceof AbstractContainer) { $this->container = new $this->containerClass(); } return $this->container; } /** * Delete a container * * @return bool */ public function deleteContainer() { if (null != $this->container) { $this->container = null; return true; } return false; } /** * Set the container class to use * * @param string $name * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return \Zend\View\Helper\Placeholder\Container\AbstractStandalone */ public function setContainerClass($name) { if (!class_exists($name)) { throw new Exception\DomainException( sprintf('%s expects a valid container class name; received "%s", which did not resolve', __METHOD__, $name )); } if (!in_array('Zend\View\Helper\Placeholder\Container\AbstractContainer', class_parents($name))) { throw new Exception\InvalidArgumentException('Invalid Container class specified'); } $this->containerClass = $name; return $this; } /** * Retrieve the container class * * @return string */ public function getContainerClass() { return $this->containerClass; } /** * Set Escaper instance * * @param Escaper $escaper * @return AbstractStandalone */ public function setEscaper(Escaper $escaper) { $encoding = $escaper->getEncoding(); $this->escapers[$encoding] = $escaper; return $this; } /** * Get Escaper instance * * Lazy-loads one if none available * * @param string|null $enc Encoding to use * @return mixed */ public function getEscaper($enc = 'UTF-8') { $enc = strtolower($enc); if (!isset($this->escapers[$enc])) { $this->setEscaper(new Escaper($enc)); } return $this->escapers[$enc]; } /** * Countable * * @return int */ public function count() { $container = $this->getContainer(); return count($container); } /** * ArrayAccess: offsetExists * * @param string|int $offset * @return bool */ public function offsetExists($offset) { return $this->getContainer()->offsetExists($offset); } /** * ArrayAccess: offsetGet * * @param string|int $offset * @return mixed */ public function offsetGet($offset) { return $this->getContainer()->offsetGet($offset); } /** * ArrayAccess: offsetSet * * @param string|int $offset * @param mixed $value * @return void */ public function offsetSet($offset, $value) { return $this->getContainer()->offsetSet($offset, $value); } /** * ArrayAccess: offsetUnset * * @param string|int $offset * @return void */ public function offsetUnset($offset) { return $this->getContainer()->offsetUnset($offset); } /** * IteratorAggregate: get Iterator * * @return Iterator */ public function getIterator() { return $this->getContainer()->getIterator(); } } |