File indexing completed on 2024-05-12 06:02:47

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_Memory
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * Zend_Memory_Container_Interface
0024  */
0025 // require_once 'Zend/Memory/Container/Interface.php';
0026 
0027 /**
0028  * Memory object container access controller.
0029  *
0030  * Memory manager stores a list of generated objects to control them.
0031  * So container objects always have at least one reference and can't be automatically destroyed.
0032  *
0033  * This class is intended to be an userland proxy to memory container object.
0034  * It's not referenced by memory manager and class destructor is invoked immidiately after gouing
0035  * out of scope or unset operation.
0036  *
0037  * Class also provides Zend_Memory_Container_Interface interface and works as proxy for such cases.
0038  *
0039  * @category   Zend
0040  * @package    Zend_Memory
0041  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0042  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0043  */
0044 class Zend_Memory_AccessController implements Zend_Memory_Container_Interface
0045 {
0046     /**
0047      * Memory container object
0048      *
0049      * @var Zend_Memory_Container
0050      */
0051     private $_memContainer;
0052 
0053 
0054     /**
0055      * Object constructor
0056      *
0057      * @param Zend_Memory_Container_Movable $memoryManager
0058      */
0059     public function __construct(Zend_Memory_Container_Movable $memContainer)
0060     {
0061         $this->_memContainer = $memContainer;
0062     }
0063 
0064     /**
0065      * Object destructor
0066      */
0067     public function __destruct()
0068     {
0069         $this->_memContainer->destroy();
0070     }
0071 
0072 
0073     /**
0074      * Get string value reference
0075      *
0076      * _Must_ be used for value access before PHP v 5.2
0077      * or _may_ be used for performance considerations
0078      *
0079      * @return &string
0080      */
0081     public function &getRef()
0082     {
0083         return $this->_memContainer->getRef();
0084     }
0085 
0086     /**
0087      * Signal, that value is updated by external code.
0088      *
0089      * Should be used together with getRef()
0090      */
0091     public function touch()
0092     {
0093         $this->_memContainer->touch();
0094     }
0095 
0096     /**
0097      * Lock object in memory.
0098      */
0099     public function lock()
0100     {
0101         $this->_memContainer->lock();
0102     }
0103 
0104 
0105     /**
0106      * Unlock object
0107      */
0108     public function unlock()
0109     {
0110         $this->_memContainer->unlock();
0111     }
0112 
0113     /**
0114      * Return true if object is locked
0115      *
0116      * @return boolean
0117      */
0118     public function isLocked()
0119     {
0120         return $this->_memContainer->isLocked();
0121     }
0122 
0123     /**
0124      * Get handler
0125      *
0126      * Loads object if necessary and moves it to the top of loaded objects list.
0127      * Swaps objects from the bottom of loaded objects list, if necessary.
0128      *
0129      * @param string $property
0130      * @return string
0131      * @throws Zend_Memory_Exception
0132      */
0133     public function __get($property)
0134     {
0135         return $this->_memContainer->$property;
0136     }
0137 
0138     /**
0139      * Set handler
0140      *
0141      * @param string $property
0142      * @param  string $value
0143      * @throws Zend_Exception
0144      */
0145     public function __set($property, $value)
0146     {
0147         $this->_memContainer->$property = $value;
0148     }
0149 }