File indexing completed on 2025-01-19 05:21:36
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_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Framework_Registry_Interface 0025 */ 0026 // require_once 'Zend/Tool/Framework/Registry/Interface.php'; 0027 0028 /** 0029 * @category Zend 0030 * @package Zend_Tool 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 */ 0034 class Zend_Tool_Framework_Registry implements Zend_Tool_Framework_Registry_Interface 0035 { 0036 /** 0037 * @var Zend_Tool_Framework_Loader_Abstract 0038 */ 0039 protected $_loader = null; 0040 0041 /** 0042 * @var Zend_Tool_Framework_Client_Abstract 0043 */ 0044 protected $_client = null; 0045 0046 /** 0047 * @var Zend_Tool_Framework_Client_Config 0048 */ 0049 protected $_config = null; 0050 0051 /** 0052 * @var Zend_Tool_Framework_Client_Storage 0053 */ 0054 protected $_storage = null; 0055 0056 /** 0057 * @var Zend_Tool_Framework_Action_Repository 0058 */ 0059 protected $_actionRepository = null; 0060 0061 /** 0062 * @var Zend_Tool_Framework_Provider_Repository 0063 */ 0064 protected $_providerRepository = null; 0065 0066 /** 0067 * @var Zend_Tool_Framework_Manifest_Repository 0068 */ 0069 protected $_manifestRepository = null; 0070 0071 /** 0072 * @var Zend_Tool_Framework_Client_Request 0073 */ 0074 protected $_request = null; 0075 0076 /** 0077 * @var Zend_Tool_Framework_Client_Response 0078 */ 0079 protected $_response = null; 0080 0081 /** 0082 * reset() - Reset all internal properties 0083 * 0084 */ 0085 public function reset() 0086 { 0087 unset($this->_client); 0088 unset($this->_loader); 0089 unset($this->_actionRepository); 0090 unset($this->_providerRepository); 0091 unset($this->_request); 0092 unset($this->_response); 0093 } 0094 0095 // public function __construct() 0096 // { 0097 // // no instantiation from outside 0098 // } 0099 0100 /** 0101 * Enter description here... 0102 * 0103 * @param Zend_Tool_Framework_Client_Abstract $client 0104 * @return Zend_Tool_Framework_Registry 0105 */ 0106 public function setClient(Zend_Tool_Framework_Client_Abstract $client) 0107 { 0108 $this->_client = $client; 0109 if ($this->isObjectRegistryEnablable($this->_client)) { 0110 $this->enableRegistryOnObject($this->_client); 0111 } 0112 return $this; 0113 } 0114 0115 /** 0116 * getClient() return the client in the registry 0117 * 0118 * @return Zend_Tool_Framework_Client_Abstract 0119 */ 0120 public function getClient() 0121 { 0122 return $this->_client; 0123 } 0124 0125 /** 0126 * setConfig() 0127 * 0128 * @param Zend_Tool_Framework_Client_Config $config 0129 * @return Zend_Tool_Framework_Registry 0130 */ 0131 public function setConfig(Zend_Tool_Framework_Client_Config $config) 0132 { 0133 $this->_config = $config; 0134 return $this; 0135 } 0136 0137 /** 0138 * getConfig() 0139 * 0140 * @return Zend_Tool_Framework_Client_Config 0141 */ 0142 public function getConfig() 0143 { 0144 if ($this->_config === null) { 0145 // require_once 'Zend/Tool/Framework/Client/Config.php'; 0146 $this->setConfig(new Zend_Tool_Framework_Client_Config()); 0147 } 0148 0149 return $this->_config; 0150 } 0151 0152 /** 0153 * setStorage() 0154 * 0155 * @param Zend_Tool_Framework_Client_Storage $storage 0156 * @return Zend_Tool_Framework_Registry 0157 */ 0158 public function setStorage(Zend_Tool_Framework_Client_Storage $storage) 0159 { 0160 $this->_storage = $storage; 0161 return $this; 0162 } 0163 0164 /** 0165 * getConfig() 0166 * 0167 * @return Zend_Tool_Framework_Client_Storage 0168 */ 0169 public function getStorage() 0170 { 0171 if ($this->_storage === null) { 0172 // require_once 'Zend/Tool/Framework/Client/Storage.php'; 0173 $this->setStorage(new Zend_Tool_Framework_Client_Storage()); 0174 } 0175 0176 return $this->_storage; 0177 } 0178 0179 /** 0180 * setLoader() 0181 * 0182 * @param Zend_Tool_Framework_Loader_Interface $loader 0183 * @return Zend_Tool_Framework_Registry 0184 */ 0185 public function setLoader(Zend_Tool_Framework_Loader_Interface $loader) 0186 { 0187 $this->_loader = $loader; 0188 if ($this->isObjectRegistryEnablable($this->_loader)) { 0189 $this->enableRegistryOnObject($this->_loader); 0190 } 0191 return $this; 0192 } 0193 0194 /** 0195 * getLoader() 0196 * 0197 * @return Zend_Tool_Framework_Loader_Abstract 0198 */ 0199 public function getLoader() 0200 { 0201 if ($this->_loader === null) { 0202 // require_once 'Zend/Tool/Framework/Loader/IncludePathLoader.php'; 0203 $this->setLoader(new Zend_Tool_Framework_Loader_IncludePathLoader()); 0204 } 0205 0206 return $this->_loader; 0207 } 0208 0209 /** 0210 * setActionRepository() 0211 * 0212 * @param Zend_Tool_Framework_Action_Repository $actionRepository 0213 * @return Zend_Tool_Framework_Registry 0214 */ 0215 public function setActionRepository(Zend_Tool_Framework_Action_Repository $actionRepository) 0216 { 0217 $this->_actionRepository = $actionRepository; 0218 if ($this->isObjectRegistryEnablable($this->_actionRepository)) { 0219 $this->enableRegistryOnObject($this->_actionRepository); 0220 } 0221 return $this; 0222 } 0223 0224 /** 0225 * getActionRepository() 0226 * 0227 * @return Zend_Tool_Framework_Action_Repository 0228 */ 0229 public function getActionRepository() 0230 { 0231 if ($this->_actionRepository == null) { 0232 // require_once 'Zend/Tool/Framework/Action/Repository.php'; 0233 $this->setActionRepository(new Zend_Tool_Framework_Action_Repository()); 0234 } 0235 0236 return $this->_actionRepository; 0237 } 0238 0239 /** 0240 * setProviderRepository() 0241 * 0242 * @param Zend_Tool_Framework_Provider_Repository $providerRepository 0243 * @return Zend_Tool_Framework_Registry 0244 */ 0245 public function setProviderRepository(Zend_Tool_Framework_Provider_Repository $providerRepository) 0246 { 0247 $this->_providerRepository = $providerRepository; 0248 if ($this->isObjectRegistryEnablable($this->_providerRepository)) { 0249 $this->enableRegistryOnObject($this->_providerRepository); 0250 } 0251 return $this; 0252 } 0253 0254 /** 0255 * getProviderRepository() 0256 * 0257 * @return Zend_Tool_Framework_Provider_Repository 0258 */ 0259 public function getProviderRepository() 0260 { 0261 if ($this->_providerRepository == null) { 0262 // require_once 'Zend/Tool/Framework/Provider/Repository.php'; 0263 $this->setProviderRepository(new Zend_Tool_Framework_Provider_Repository()); 0264 } 0265 0266 return $this->_providerRepository; 0267 } 0268 0269 /** 0270 * setManifestRepository() 0271 * 0272 * @param Zend_Tool_Framework_Manifest_Repository $manifestRepository 0273 * @return Zend_Tool_Framework_Registry 0274 */ 0275 public function setManifestRepository(Zend_Tool_Framework_Manifest_Repository $manifestRepository) 0276 { 0277 $this->_manifestRepository = $manifestRepository; 0278 if ($this->isObjectRegistryEnablable($this->_manifestRepository)) { 0279 $this->enableRegistryOnObject($this->_manifestRepository); 0280 } 0281 return $this; 0282 } 0283 0284 /** 0285 * getManifestRepository() 0286 * 0287 * @return Zend_Tool_Framework_Manifest_Repository 0288 */ 0289 public function getManifestRepository() 0290 { 0291 if ($this->_manifestRepository == null) { 0292 // require_once 'Zend/Tool/Framework/Manifest/Repository.php'; 0293 $this->setManifestRepository(new Zend_Tool_Framework_Manifest_Repository()); 0294 } 0295 0296 return $this->_manifestRepository; 0297 } 0298 0299 /** 0300 * setRequest() 0301 * 0302 * @param Zend_Tool_Framework_Client_Request $request 0303 * @return Zend_Tool_Framework_Registry 0304 */ 0305 public function setRequest(Zend_Tool_Framework_Client_Request $request) 0306 { 0307 $this->_request = $request; 0308 return $this; 0309 } 0310 0311 /** 0312 * getRequest() 0313 * 0314 * @return Zend_Tool_Framework_Client_Request 0315 */ 0316 public function getRequest() 0317 { 0318 if ($this->_request == null) { 0319 // require_once 'Zend/Tool/Framework/Client/Request.php'; 0320 $this->setRequest(new Zend_Tool_Framework_Client_Request()); 0321 } 0322 0323 return $this->_request; 0324 } 0325 0326 /** 0327 * setResponse() 0328 * 0329 * @param Zend_Tool_Framework_Client_Response $response 0330 * @return Zend_Tool_Framework_Registry 0331 */ 0332 public function setResponse(Zend_Tool_Framework_Client_Response $response) 0333 { 0334 $this->_response = $response; 0335 return $this; 0336 } 0337 0338 /** 0339 * getResponse() 0340 * 0341 * @return Zend_Tool_Framework_Client_Response 0342 */ 0343 public function getResponse() 0344 { 0345 if ($this->_response == null) { 0346 // require_once 'Zend/Tool/Framework/Client/Response.php'; 0347 $this->setResponse(new Zend_Tool_Framework_Client_Response()); 0348 } 0349 0350 return $this->_response; 0351 } 0352 0353 /** 0354 * __get() - Get a property via property call $registry->foo 0355 * 0356 * @param string $name 0357 * @return mixed 0358 */ 0359 public function __get($name) 0360 { 0361 if (method_exists($this, 'get' . $name)) { 0362 return $this->{'get' . $name}(); 0363 } else { 0364 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0365 throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.'); 0366 } 0367 } 0368 0369 /** 0370 * __set() - Set a property via the magic set $registry->foo = 'foo' 0371 * 0372 * @param string $name 0373 * @param mixed $value 0374 */ 0375 public function __set($name, $value) 0376 { 0377 if (method_exists($this, 'set' . $name)) { 0378 $this->{'set' . $name}($value); 0379 return; 0380 } else { 0381 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0382 throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.'); 0383 } 0384 } 0385 0386 /** 0387 * isObjectRegistryEnablable() - Check whether an object is registry enablable 0388 * 0389 * @param object $object 0390 * @return bool 0391 */ 0392 public function isObjectRegistryEnablable($object) 0393 { 0394 if (!is_object($object)) { 0395 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0396 throw new Zend_Tool_Framework_Registry_Exception('isObjectRegistryEnablable() expects an object.'); 0397 } 0398 0399 return ($object instanceof Zend_Tool_Framework_Registry_EnabledInterface); 0400 } 0401 0402 /** 0403 * enableRegistryOnObject() - make an object registry enabled 0404 * 0405 * @param object $object 0406 * @return Zend_Tool_Framework_Registry 0407 */ 0408 public function enableRegistryOnObject($object) 0409 { 0410 if (!$this->isObjectRegistryEnablable($object)) { 0411 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0412 throw new Zend_Tool_Framework_Registry_Exception('Object provided is not registry enablable, check first with Zend_Tool_Framework_Registry::isObjectRegistryEnablable()'); 0413 } 0414 0415 $object->setRegistry($this); 0416 return $this; 0417 } 0418 0419 }