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.
17 * @subpackage Framework
18 * @copyright Copyright (c) 2005-2009 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 16972 2009-07-22 18:44:24Z ralph $
24 * @see Zend_Tool_Framework_Registry_Interface
26 require_once 'Zend/Tool/Framework/Registry/Interface.php';
31 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
34 class Zend_Tool_Framework_Registry
implements Zend_Tool_Framework_Registry_Interface
37 * @var Zend_Tool_Framework_Loader_Abstract
39 protected $_loader = null;
42 * @var Zend_Tool_Framework_Client_Abstract
44 protected $_client = null;
47 * @var Zend_Tool_Framework_Client_Config
49 protected $_config = null;
52 * @var Zend_Tool_Framework_Client_Storage
54 protected $_storage = null;
57 * @var Zend_Tool_Framework_Action_Repository
59 protected $_actionRepository = null;
62 * @var Zend_Tool_Framework_Provider_Repository
64 protected $_providerRepository = null;
67 * @var Zend_Tool_Framework_Manifest_Repository
69 protected $_manifestRepository = null;
72 * @var Zend_Tool_Framework_Client_Request
74 protected $_request = null;
77 * @var Zend_Tool_Framework_Client_Response
79 protected $_response = null;
82 * reset() - Reset all internal properties
85 public function reset()
87 unset($this->_client
);
88 unset($this->_loader
);
89 unset($this->_actionRepository
);
90 unset($this->_providerRepository
);
91 unset($this->_request
);
92 unset($this->_response
);
95 // public function __construct()
97 // // no instantiation from outside
101 * Enter description here...
103 * @param Zend_Tool_Framework_Client_Abstract $client
104 * @return Zend_Tool_Framework_Registry
106 public function setClient(Zend_Tool_Framework_Client_Abstract
$client)
108 $this->_client
= $client;
109 if ($this->isObjectRegistryEnablable($this->_client
)) {
110 $this->enableRegistryOnObject($this->_client
);
116 * getClient() return the client in the registry
118 * @return Zend_Tool_Framework_Client_Abstract
120 public function getClient()
122 return $this->_client
;
128 * @param Zend_Tool_Framework_Client_Config $config
129 * @return Zend_Tool_Framework_Registry
131 public function setConfig(Zend_Tool_Framework_Client_Config
$config)
133 $this->_config
= $config;
140 * @return Zend_Tool_Framework_Client_Config
142 public function getConfig()
144 if ($this->_config
=== null) {
145 require_once 'Zend/Tool/Framework/Client/Config.php';
146 $this->setConfig(new Zend_Tool_Framework_Client_Config());
149 return $this->_config
;
155 * @param Zend_Tool_Framework_Client_Storage $storage
156 * @return Zend_Tool_Framework_Registry
158 public function setStorage(Zend_Tool_Framework_Client_Storage
$storage)
160 $this->_storage
= $storage;
167 * @return Zend_Tool_Framework_Client_Storage
169 public function getStorage()
171 if ($this->_storage
=== null) {
172 require_once 'Zend/Tool/Framework/Client/Storage.php';
173 $this->setStorage(new Zend_Tool_Framework_Client_Storage());
176 return $this->_storage
;
182 * @param Zend_Tool_Framework_Loader_Abstract $loader
183 * @return Zend_Tool_Framework_Registry
185 public function setLoader(Zend_Tool_Framework_Loader_Abstract
$loader)
187 $this->_loader
= $loader;
188 if ($this->isObjectRegistryEnablable($this->_loader
)) {
189 $this->enableRegistryOnObject($this->_loader
);
197 * @return Zend_Tool_Framework_Loader_Abstract
199 public function getLoader()
201 if ($this->_loader
=== null) {
202 require_once 'Zend/Tool/Framework/Loader/IncludePathLoader.php';
203 $this->setLoader(new Zend_Tool_Framework_Loader_IncludePathLoader());
206 return $this->_loader
;
210 * setActionRepository()
212 * @param Zend_Tool_Framework_Action_Repository $actionRepository
213 * @return Zend_Tool_Framework_Registry
215 public function setActionRepository(Zend_Tool_Framework_Action_Repository
$actionRepository)
217 $this->_actionRepository
= $actionRepository;
218 if ($this->isObjectRegistryEnablable($this->_actionRepository
)) {
219 $this->enableRegistryOnObject($this->_actionRepository
);
225 * getActionRepository()
227 * @return Zend_Tool_Framework_Action_Repository
229 public function getActionRepository()
231 if ($this->_actionRepository
== null) {
232 require_once 'Zend/Tool/Framework/Action/Repository.php';
233 $this->setActionRepository(new Zend_Tool_Framework_Action_Repository());
236 return $this->_actionRepository
;
240 * setProviderRepository()
242 * @param Zend_Tool_Framework_Provider_Repository $providerRepository
243 * @return Zend_Tool_Framework_Registry
245 public function setProviderRepository(Zend_Tool_Framework_Provider_Repository
$providerRepository)
247 $this->_providerRepository
= $providerRepository;
248 if ($this->isObjectRegistryEnablable($this->_providerRepository
)) {
249 $this->enableRegistryOnObject($this->_providerRepository
);
255 * getProviderRepository()
257 * @return Zend_Tool_Framework_Provider_Repository
259 public function getProviderRepository()
261 if ($this->_providerRepository
== null) {
262 require_once 'Zend/Tool/Framework/Provider/Repository.php';
263 $this->setProviderRepository(new Zend_Tool_Framework_Provider_Repository());
266 return $this->_providerRepository
;
270 * setManifestRepository()
272 * @param Zend_Tool_Framework_Manifest_Repository $manifestRepository
273 * @return Zend_Tool_Framework_Registry
275 public function setManifestRepository(Zend_Tool_Framework_Manifest_Repository
$manifestRepository)
277 $this->_manifestRepository
= $manifestRepository;
278 if ($this->isObjectRegistryEnablable($this->_manifestRepository
)) {
279 $this->enableRegistryOnObject($this->_manifestRepository
);
285 * getManifestRepository()
287 * @return Zend_Tool_Framework_Manifest_Repository
289 public function getManifestRepository()
291 if ($this->_manifestRepository
== null) {
292 require_once 'Zend/Tool/Framework/Manifest/Repository.php';
293 $this->setManifestRepository(new Zend_Tool_Framework_Manifest_Repository());
296 return $this->_manifestRepository
;
302 * @param Zend_Tool_Framework_Client_Request $request
303 * @return Zend_Tool_Framework_Registry
305 public function setRequest(Zend_Tool_Framework_Client_Request
$request)
307 $this->_request
= $request;
314 * @return Zend_Tool_Framework_Client_Request
316 public function getRequest()
318 if ($this->_request
== null) {
319 require_once 'Zend/Tool/Framework/Client/Request.php';
320 $this->setRequest(new Zend_Tool_Framework_Client_Request());
323 return $this->_request
;
329 * @param Zend_Tool_Framework_Client_Response $response
330 * @return Zend_Tool_Framework_Registry
332 public function setResponse(Zend_Tool_Framework_Client_Response
$response)
334 $this->_response
= $response;
341 * @return Zend_Tool_Framework_Client_Response
343 public function getResponse()
345 if ($this->_response
== null) {
346 require_once 'Zend/Tool/Framework/Client/Response.php';
347 $this->setResponse(new Zend_Tool_Framework_Client_Response());
350 return $this->_response
;
354 * __get() - Get a property via property call $registry->foo
356 * @param string $name
359 public function __get($name)
361 if (method_exists($this, 'get' . $name)) {
362 return $this->{'get' . $name}();
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.');
370 * __set() - Set a property via the magic set $registry->foo = 'foo'
372 * @param string $name
373 * @param mixed $value
375 public function __set($name, $value)
377 if (method_exists($this, 'set' . $name)) {
378 $this->{'set' . $name}($value);
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.');
387 * isObjectRegistryEnablable() - Check whether an object is registry enablable
389 * @param object $object
392 public function isObjectRegistryEnablable($object)
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.');
399 return ($object instanceof Zend_Tool_Framework_Registry_EnabledInterface
);
403 * enableRegistryOnObject() - make an object registry enabled
405 * @param object $object
406 * @return Zend_Tool_Framework_Registry
408 public function enableRegistryOnObject($object)
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()');
415 $object->setRegistry($this);