web/lib/Zend/Tool/Framework/Registry.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Registry.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Framework_Registry_Interface
       
    25  */
       
    26 require_once 'Zend/Tool/Framework/Registry/Interface.php';
       
    27 
       
    28 /**
       
    29  * @category   Zend
       
    30  * @package    Zend_Tool
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  */
       
    34 class Zend_Tool_Framework_Registry implements Zend_Tool_Framework_Registry_Interface
       
    35 {
       
    36     /**
       
    37      * @var Zend_Tool_Framework_Loader_Abstract
       
    38      */
       
    39     protected $_loader = null;
       
    40 
       
    41     /**
       
    42      * @var Zend_Tool_Framework_Client_Abstract
       
    43      */
       
    44     protected $_client = null;
       
    45 
       
    46     /**
       
    47      * @var Zend_Tool_Framework_Client_Config
       
    48      */
       
    49     protected $_config = null;
       
    50 
       
    51     /**
       
    52      * @var Zend_Tool_Framework_Client_Storage
       
    53      */
       
    54     protected $_storage = null;
       
    55 
       
    56     /**
       
    57      * @var Zend_Tool_Framework_Action_Repository
       
    58      */
       
    59     protected $_actionRepository = null;
       
    60 
       
    61     /**
       
    62      * @var Zend_Tool_Framework_Provider_Repository
       
    63      */
       
    64     protected $_providerRepository = null;
       
    65 
       
    66     /**
       
    67      * @var Zend_Tool_Framework_Manifest_Repository
       
    68      */
       
    69     protected $_manifestRepository = null;
       
    70 
       
    71     /**
       
    72      * @var Zend_Tool_Framework_Client_Request
       
    73      */
       
    74     protected $_request = null;
       
    75 
       
    76     /**
       
    77      * @var Zend_Tool_Framework_Client_Response
       
    78      */
       
    79     protected $_response = null;
       
    80 
       
    81     /**
       
    82      * reset() - Reset all internal properties
       
    83      *
       
    84      */
       
    85     public function reset()
       
    86     {
       
    87         unset($this->_client);
       
    88         unset($this->_loader);
       
    89         unset($this->_actionRepository);
       
    90         unset($this->_providerRepository);
       
    91         unset($this->_request);
       
    92         unset($this->_response);
       
    93     }
       
    94 
       
    95 //    public function __construct()
       
    96 //    {
       
    97 //        // no instantiation from outside
       
    98 //    }
       
    99 
       
   100     /**
       
   101      * Enter description here...
       
   102      *
       
   103      * @param Zend_Tool_Framework_Client_Abstract $client
       
   104      * @return Zend_Tool_Framework_Registry
       
   105      */
       
   106     public function setClient(Zend_Tool_Framework_Client_Abstract $client)
       
   107     {
       
   108         $this->_client = $client;
       
   109         if ($this->isObjectRegistryEnablable($this->_client)) {
       
   110             $this->enableRegistryOnObject($this->_client);
       
   111         }
       
   112         return $this;
       
   113     }
       
   114 
       
   115     /**
       
   116      * getClient() return the client in the registry
       
   117      *
       
   118      * @return Zend_Tool_Framework_Client_Abstract
       
   119      */
       
   120     public function getClient()
       
   121     {
       
   122         return $this->_client;
       
   123     }
       
   124 
       
   125     /**
       
   126      * setConfig()
       
   127      *
       
   128      * @param Zend_Tool_Framework_Client_Config $config
       
   129      * @return Zend_Tool_Framework_Registry
       
   130      */
       
   131     public function setConfig(Zend_Tool_Framework_Client_Config $config)
       
   132     {
       
   133         $this->_config = $config;
       
   134         return $this;
       
   135     }
       
   136 
       
   137     /**
       
   138      * getConfig()
       
   139      *
       
   140      * @return Zend_Tool_Framework_Client_Config
       
   141      */
       
   142     public function getConfig()
       
   143     {
       
   144         if ($this->_config === null) {
       
   145             require_once 'Zend/Tool/Framework/Client/Config.php';
       
   146             $this->setConfig(new Zend_Tool_Framework_Client_Config());
       
   147         }
       
   148 
       
   149         return $this->_config;
       
   150     }
       
   151 
       
   152     /**
       
   153      * setStorage()
       
   154      *
       
   155      * @param Zend_Tool_Framework_Client_Storage $storage
       
   156      * @return Zend_Tool_Framework_Registry
       
   157      */
       
   158     public function setStorage(Zend_Tool_Framework_Client_Storage $storage)
       
   159     {
       
   160         $this->_storage = $storage;
       
   161         return $this;
       
   162     }
       
   163 
       
   164     /**
       
   165      * getConfig()
       
   166      *
       
   167      * @return Zend_Tool_Framework_Client_Storage
       
   168      */
       
   169     public function getStorage()
       
   170     {
       
   171         if ($this->_storage === null) {
       
   172             require_once 'Zend/Tool/Framework/Client/Storage.php';
       
   173             $this->setStorage(new Zend_Tool_Framework_Client_Storage());
       
   174         }
       
   175 
       
   176         return $this->_storage;
       
   177     }
       
   178 
       
   179     /**
       
   180      * setLoader()
       
   181      *
       
   182      * @param Zend_Tool_Framework_Loader_Interface $loader
       
   183      * @return Zend_Tool_Framework_Registry
       
   184      */
       
   185     public function setLoader(Zend_Tool_Framework_Loader_Interface $loader)
       
   186     {
       
   187         $this->_loader = $loader;
       
   188         if ($this->isObjectRegistryEnablable($this->_loader)) {
       
   189             $this->enableRegistryOnObject($this->_loader);
       
   190         }
       
   191         return $this;
       
   192     }
       
   193 
       
   194     /**
       
   195      * getLoader()
       
   196      *
       
   197      * @return Zend_Tool_Framework_Loader_Abstract
       
   198      */
       
   199     public function getLoader()
       
   200     {
       
   201         if ($this->_loader === null) {
       
   202             require_once 'Zend/Tool/Framework/Loader/IncludePathLoader.php';
       
   203             $this->setLoader(new Zend_Tool_Framework_Loader_IncludePathLoader());
       
   204         }
       
   205 
       
   206         return $this->_loader;
       
   207     }
       
   208 
       
   209     /**
       
   210      * setActionRepository()
       
   211      *
       
   212      * @param Zend_Tool_Framework_Action_Repository $actionRepository
       
   213      * @return Zend_Tool_Framework_Registry
       
   214      */
       
   215     public function setActionRepository(Zend_Tool_Framework_Action_Repository $actionRepository)
       
   216     {
       
   217         $this->_actionRepository = $actionRepository;
       
   218         if ($this->isObjectRegistryEnablable($this->_actionRepository)) {
       
   219             $this->enableRegistryOnObject($this->_actionRepository);
       
   220         }
       
   221         return $this;
       
   222     }
       
   223 
       
   224     /**
       
   225      * getActionRepository()
       
   226      *
       
   227      * @return Zend_Tool_Framework_Action_Repository
       
   228      */
       
   229     public function getActionRepository()
       
   230     {
       
   231         if ($this->_actionRepository == null) {
       
   232             require_once 'Zend/Tool/Framework/Action/Repository.php';
       
   233             $this->setActionRepository(new Zend_Tool_Framework_Action_Repository());
       
   234         }
       
   235 
       
   236         return $this->_actionRepository;
       
   237     }
       
   238 
       
   239     /**
       
   240      * setProviderRepository()
       
   241      *
       
   242      * @param Zend_Tool_Framework_Provider_Repository $providerRepository
       
   243      * @return Zend_Tool_Framework_Registry
       
   244      */
       
   245     public function setProviderRepository(Zend_Tool_Framework_Provider_Repository $providerRepository)
       
   246     {
       
   247         $this->_providerRepository = $providerRepository;
       
   248         if ($this->isObjectRegistryEnablable($this->_providerRepository)) {
       
   249             $this->enableRegistryOnObject($this->_providerRepository);
       
   250         }
       
   251         return $this;
       
   252     }
       
   253 
       
   254     /**
       
   255      * getProviderRepository()
       
   256      *
       
   257      * @return Zend_Tool_Framework_Provider_Repository
       
   258      */
       
   259     public function getProviderRepository()
       
   260     {
       
   261         if ($this->_providerRepository == null) {
       
   262             require_once 'Zend/Tool/Framework/Provider/Repository.php';
       
   263             $this->setProviderRepository(new Zend_Tool_Framework_Provider_Repository());
       
   264         }
       
   265 
       
   266         return $this->_providerRepository;
       
   267     }
       
   268 
       
   269     /**
       
   270      * setManifestRepository()
       
   271      *
       
   272      * @param Zend_Tool_Framework_Manifest_Repository $manifestRepository
       
   273      * @return Zend_Tool_Framework_Registry
       
   274      */
       
   275     public function setManifestRepository(Zend_Tool_Framework_Manifest_Repository $manifestRepository)
       
   276     {
       
   277         $this->_manifestRepository = $manifestRepository;
       
   278         if ($this->isObjectRegistryEnablable($this->_manifestRepository)) {
       
   279             $this->enableRegistryOnObject($this->_manifestRepository);
       
   280         }
       
   281         return $this;
       
   282     }
       
   283 
       
   284     /**
       
   285      * getManifestRepository()
       
   286      *
       
   287      * @return Zend_Tool_Framework_Manifest_Repository
       
   288      */
       
   289     public function getManifestRepository()
       
   290     {
       
   291         if ($this->_manifestRepository == null) {
       
   292             require_once 'Zend/Tool/Framework/Manifest/Repository.php';
       
   293             $this->setManifestRepository(new Zend_Tool_Framework_Manifest_Repository());
       
   294         }
       
   295 
       
   296         return $this->_manifestRepository;
       
   297     }
       
   298 
       
   299     /**
       
   300      * setRequest()
       
   301      *
       
   302      * @param Zend_Tool_Framework_Client_Request $request
       
   303      * @return Zend_Tool_Framework_Registry
       
   304      */
       
   305     public function setRequest(Zend_Tool_Framework_Client_Request $request)
       
   306     {
       
   307         $this->_request = $request;
       
   308         return $this;
       
   309     }
       
   310 
       
   311     /**
       
   312      * getRequest()
       
   313      *
       
   314      * @return Zend_Tool_Framework_Client_Request
       
   315      */
       
   316     public function getRequest()
       
   317     {
       
   318         if ($this->_request == null) {
       
   319             require_once 'Zend/Tool/Framework/Client/Request.php';
       
   320             $this->setRequest(new Zend_Tool_Framework_Client_Request());
       
   321         }
       
   322 
       
   323         return $this->_request;
       
   324     }
       
   325 
       
   326     /**
       
   327      * setResponse()
       
   328      *
       
   329      * @param Zend_Tool_Framework_Client_Response $response
       
   330      * @return Zend_Tool_Framework_Registry
       
   331      */
       
   332     public function setResponse(Zend_Tool_Framework_Client_Response $response)
       
   333     {
       
   334         $this->_response = $response;
       
   335         return $this;
       
   336     }
       
   337 
       
   338     /**
       
   339      * getResponse()
       
   340      *
       
   341      * @return Zend_Tool_Framework_Client_Response
       
   342      */
       
   343     public function getResponse()
       
   344     {
       
   345         if ($this->_response == null) {
       
   346             require_once 'Zend/Tool/Framework/Client/Response.php';
       
   347             $this->setResponse(new Zend_Tool_Framework_Client_Response());
       
   348         }
       
   349 
       
   350         return $this->_response;
       
   351     }
       
   352 
       
   353     /**
       
   354      * __get() - Get a property via property call $registry->foo
       
   355      *
       
   356      * @param string $name
       
   357      * @return mixed
       
   358      */
       
   359     public function __get($name)
       
   360     {
       
   361         if (method_exists($this, 'get' . $name)) {
       
   362             return $this->{'get' . $name}();
       
   363         } else {
       
   364             require_once 'Zend/Tool/Framework/Registry/Exception.php';
       
   365             throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
       
   366         }
       
   367     }
       
   368 
       
   369     /**
       
   370      * __set() - Set a property via the magic set $registry->foo = 'foo'
       
   371      *
       
   372      * @param string $name
       
   373      * @param mixed $value
       
   374      */
       
   375     public function __set($name, $value)
       
   376     {
       
   377         if (method_exists($this, 'set' . $name)) {
       
   378             $this->{'set' . $name}($value);
       
   379             return;
       
   380         } else {
       
   381             require_once 'Zend/Tool/Framework/Registry/Exception.php';
       
   382             throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
       
   383         }
       
   384     }
       
   385 
       
   386     /**
       
   387      * isObjectRegistryEnablable() - Check whether an object is registry enablable
       
   388      *
       
   389      * @param object $object
       
   390      * @return bool
       
   391      */
       
   392     public function isObjectRegistryEnablable($object)
       
   393     {
       
   394         if (!is_object($object)) {
       
   395             require_once 'Zend/Tool/Framework/Registry/Exception.php';
       
   396             throw new Zend_Tool_Framework_Registry_Exception('isObjectRegistryEnablable() expects an object.');
       
   397         }
       
   398 
       
   399         return ($object instanceof Zend_Tool_Framework_Registry_EnabledInterface);
       
   400     }
       
   401 
       
   402     /**
       
   403      * enableRegistryOnObject() - make an object registry enabled
       
   404      *
       
   405      * @param object $object
       
   406      * @return Zend_Tool_Framework_Registry
       
   407      */
       
   408     public function enableRegistryOnObject($object)
       
   409     {
       
   410         if (!$this->isObjectRegistryEnablable($object)) {
       
   411             require_once 'Zend/Tool/Framework/Registry/Exception.php';
       
   412             throw new Zend_Tool_Framework_Registry_Exception('Object provided is not registry enablable, check first with Zend_Tool_Framework_Registry::isObjectRegistryEnablable()');
       
   413         }
       
   414 
       
   415         $object->setRegistry($this);
       
   416         return $this;
       
   417     }
       
   418 
       
   419 }