File indexing completed on 2025-03-02 05:29:58

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_View
0017  * @subpackage Helper
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @version    $Id$
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  */
0022 
0023 /** Zend_View_Helper_Placeholder_Registry */
0024 // require_once 'Zend/View/Helper/Placeholder/Registry.php';
0025 
0026 /** Zend_View_Helper_Abstract.php */
0027 // require_once 'Zend/View/Helper/Abstract.php';
0028 
0029 /**
0030  * Base class for targetted placeholder helpers
0031  *
0032  * @package    Zend_View
0033  * @subpackage Helper
0034  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0035  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0036  */
0037 abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_View_Helper_Abstract implements IteratorAggregate, Countable, ArrayAccess
0038 {
0039     /**
0040      * @var Zend_View_Helper_Placeholder_Container_Abstract
0041      */
0042     protected $_container;
0043 
0044     /**
0045      * @var Zend_View_Helper_Placeholder_Registry
0046      */
0047     protected $_registry;
0048 
0049     /**
0050      * Registry key under which container registers itself
0051      * @var string
0052      */
0053     protected $_regKey;
0054 
0055     /**
0056      * Flag wheter to automatically escape output, must also be
0057      * enforced in the child class if __toString/toString is overriden
0058      * @var book
0059      */
0060     protected $_autoEscape = true;
0061 
0062     /**
0063      * Constructor
0064      *
0065      * @return void
0066      */
0067     public function __construct()
0068     {
0069         $this->setRegistry(Zend_View_Helper_Placeholder_Registry::getRegistry());
0070         $this->setContainer($this->getRegistry()->getContainer($this->_regKey));
0071     }
0072 
0073     /**
0074      * Retrieve registry
0075      *
0076      * @return Zend_View_Helper_Placeholder_Registry
0077      */
0078     public function getRegistry()
0079     {
0080         return $this->_registry;
0081     }
0082 
0083     /**
0084      * Set registry object
0085      *
0086      * @param  Zend_View_Helper_Placeholder_Registry $registry
0087      * @return Zend_View_Helper_Placeholder_Container_Standalone
0088      */
0089     public function setRegistry(Zend_View_Helper_Placeholder_Registry $registry)
0090     {
0091         $this->_registry = $registry;
0092         return $this;
0093     }
0094 
0095     /**
0096      * Set whether or not auto escaping should be used
0097      *
0098      * @param  bool $autoEscape whether or not to auto escape output
0099      * @return Zend_View_Helper_Placeholder_Container_Standalone
0100      */
0101     public function setAutoEscape($autoEscape = true)
0102     {
0103         $this->_autoEscape = ($autoEscape) ? true : false;
0104         return $this;
0105     }
0106 
0107     /**
0108      * Return whether autoEscaping is enabled or disabled
0109      *
0110      * return bool
0111      */
0112     public function getAutoEscape()
0113     {
0114         return $this->_autoEscape;
0115     }
0116 
0117     /**
0118      * Escape a string
0119      *
0120      * @param  string $string
0121      * @return string
0122      */
0123     protected function _escape($string)
0124     {
0125         $enc = 'UTF-8';
0126         if ($this->view instanceof Zend_View_Interface
0127             && method_exists($this->view, 'getEncoding')
0128         ) {
0129             $enc = $this->view->getEncoding();
0130         }
0131 
0132         return htmlspecialchars((string) $string, ENT_COMPAT, $enc);
0133     }
0134 
0135     /**
0136      * Set container on which to operate
0137      *
0138      * @param  Zend_View_Helper_Placeholder_Container_Abstract $container
0139      * @return Zend_View_Helper_Placeholder_Container_Standalone
0140      */
0141     public function setContainer(Zend_View_Helper_Placeholder_Container_Abstract $container)
0142     {
0143         $this->_container = $container;
0144         return $this;
0145     }
0146 
0147     /**
0148      * Retrieve placeholder container
0149      *
0150      * @return Zend_View_Helper_Placeholder_Container_Abstract
0151      */
0152     public function getContainer()
0153     {
0154         return $this->_container;
0155     }
0156 
0157     /**
0158      * Overloading: set property value
0159      *
0160      * @param  string $key
0161      * @param  mixed $value
0162      * @return void
0163      */
0164     public function __set($key, $value)
0165     {
0166         $container = $this->getContainer();
0167         $container[$key] = $value;
0168     }
0169 
0170     /**
0171      * Overloading: retrieve property
0172      *
0173      * @param  string $key
0174      * @return mixed
0175      */
0176     public function __get($key)
0177     {
0178         $container = $this->getContainer();
0179         if (isset($container[$key])) {
0180             return $container[$key];
0181         }
0182 
0183         return null;
0184     }
0185 
0186     /**
0187      * Overloading: check if property is set
0188      *
0189      * @param  string $key
0190      * @return bool
0191      */
0192     public function __isset($key)
0193     {
0194         $container = $this->getContainer();
0195         return isset($container[$key]);
0196     }
0197 
0198     /**
0199      * Overloading: unset property
0200      *
0201      * @param  string $key
0202      * @return void
0203      */
0204     public function __unset($key)
0205     {
0206         $container = $this->getContainer();
0207         if (isset($container[$key])) {
0208             unset($container[$key]);
0209         }
0210     }
0211 
0212     /**
0213      * Overload
0214      *
0215      * Proxy to container methods
0216      *
0217      * @param  string $method
0218      * @param  array $args
0219      * @return mixed
0220      */
0221     public function __call($method, $args)
0222     {
0223         $container = $this->getContainer();
0224         if (method_exists($container, $method)) {
0225             $return = call_user_func_array(array($container, $method), $args);
0226             if ($return === $container) {
0227                 // If the container is returned, we really want the current object
0228                 return $this;
0229             }
0230             return $return;
0231         }
0232 
0233         // require_once 'Zend/View/Exception.php';
0234         $e = new Zend_View_Exception('Method "' . $method . '" does not exist');
0235         $e->setView($this->view);
0236         throw $e;
0237     }
0238 
0239     /**
0240      * String representation
0241      *
0242      * @return string
0243      */
0244     public function toString()
0245     {
0246         return $this->getContainer()->toString();
0247     }
0248 
0249     /**
0250      * Cast to string representation
0251      *
0252      * @return string
0253      */
0254     public function __toString()
0255     {
0256         return $this->toString();
0257     }
0258 
0259     /**
0260      * Countable
0261      *
0262      * @return int
0263      */
0264     public function count()
0265     {
0266         $container = $this->getContainer();
0267         return count($container);
0268     }
0269 
0270     /**
0271      * ArrayAccess: offsetExists
0272      *
0273      * @param  string|int $offset
0274      * @return bool
0275      */
0276     public function offsetExists($offset)
0277     {
0278         return $this->getContainer()->offsetExists($offset);
0279     }
0280 
0281     /**
0282      * ArrayAccess: offsetGet
0283      *
0284      * @param  string|int $offset
0285      * @return mixed
0286      */
0287     public function offsetGet($offset)
0288     {
0289         return $this->getContainer()->offsetGet($offset);
0290     }
0291 
0292     /**
0293      * ArrayAccess: offsetSet
0294      *
0295      * @param  string|int $offset
0296      * @param  mixed $value
0297      * @return void
0298      */
0299     public function offsetSet($offset, $value)
0300     {
0301         return $this->getContainer()->offsetSet($offset, $value);
0302     }
0303 
0304     /**
0305      * ArrayAccess: offsetUnset
0306      *
0307      * @param  string|int $offset
0308      * @return void
0309      */
0310     public function offsetUnset($offset)
0311     {
0312         return $this->getContainer()->offsetUnset($offset);
0313     }
0314 
0315     /**
0316      * IteratorAggregate: get Iterator
0317      *
0318      * @return Iterator
0319      */
0320     public function getIterator()
0321     {
0322         return $this->getContainer()->getIterator();
0323     }
0324 }