2
0

Registry.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Framework_Registry_Interface
  24. */
  25. require_once 'Zend/Tool/Framework/Registry/Interface.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Framework_Registry implements Zend_Tool_Framework_Registry_Interface
  33. {
  34. /**
  35. * @var Zend_Tool_Framework_Loader_Abstract
  36. */
  37. protected $_loader = null;
  38. /**
  39. * @var Zend_Tool_Framework_Client_Abstract
  40. */
  41. protected $_client = null;
  42. /**
  43. * @var Zend_Tool_Framework_Action_Repository
  44. */
  45. protected $_actionRepository = null;
  46. /**
  47. * @var Zend_Tool_Framework_Provider_Repository
  48. */
  49. protected $_providerRepository = null;
  50. /**
  51. * @var Zend_Tool_Framework_Manifest_Repository
  52. */
  53. protected $_manifestRepository = null;
  54. /**
  55. * @var Zend_Tool_Framework_Client_Request
  56. */
  57. protected $_request = null;
  58. /**
  59. * @var Zend_Tool_Framework_Client_Response
  60. */
  61. protected $_response = null;
  62. /**
  63. * reset() - Reset all internal properties
  64. *
  65. */
  66. public function reset()
  67. {
  68. unset($this->_client);
  69. unset($this->_loader);
  70. unset($this->_actionRepository);
  71. unset($this->_providerRepository);
  72. unset($this->_request);
  73. unset($this->_response);
  74. }
  75. // public function __construct()
  76. // {
  77. // // no instantiation from outside
  78. // }
  79. /**
  80. * Enter description here...
  81. *
  82. * @param Zend_Tool_Framework_Client_Abstract $client
  83. * @return Zend_Tool_Framework_Registry
  84. */
  85. public function setClient(Zend_Tool_Framework_Client_Abstract $client)
  86. {
  87. $this->_client = $client;
  88. if ($this->isObjectRegistryEnablable($this->_client)) {
  89. $this->enableRegistryOnObject($this->_client);
  90. }
  91. return $this;
  92. }
  93. /**
  94. * getClient() return the client in the registry
  95. *
  96. * @return Zend_Tool_Framework_Client_Abstract
  97. */
  98. public function getClient()
  99. {
  100. return $this->_client;
  101. }
  102. /**
  103. * setLoader()
  104. *
  105. * @param Zend_Tool_Framework_Loader_Abstract $loader
  106. * @return Zend_Tool_Framework_Registry
  107. */
  108. public function setLoader(Zend_Tool_Framework_Loader_Abstract $loader)
  109. {
  110. $this->_loader = $loader;
  111. if ($this->isObjectRegistryEnablable($this->_loader)) {
  112. $this->enableRegistryOnObject($this->_loader);
  113. }
  114. return $this;
  115. }
  116. /**
  117. * getLoader()
  118. *
  119. * @return Zend_Tool_Framework_Loader_Abstract
  120. */
  121. public function getLoader()
  122. {
  123. if ($this->_loader === null) {
  124. require_once 'Zend/Tool/Framework/Loader/IncludePathLoader.php';
  125. $this->setLoader(new Zend_Tool_Framework_Loader_IncludePathLoader());
  126. }
  127. return $this->_loader;
  128. }
  129. /**
  130. * setActionRepository()
  131. *
  132. * @param Zend_Tool_Framework_Action_Repository $actionRepository
  133. * @return Zend_Tool_Framework_Registry
  134. */
  135. public function setActionRepository(Zend_Tool_Framework_Action_Repository $actionRepository)
  136. {
  137. $this->_actionRepository = $actionRepository;
  138. if ($this->isObjectRegistryEnablable($this->_actionRepository)) {
  139. $this->enableRegistryOnObject($this->_actionRepository);
  140. }
  141. return $this;
  142. }
  143. /**
  144. * getActionRepository()
  145. *
  146. * @return Zend_Tool_Framework_Action_Repository
  147. */
  148. public function getActionRepository()
  149. {
  150. if ($this->_actionRepository == null) {
  151. require_once 'Zend/Tool/Framework/Action/Repository.php';
  152. $this->setActionRepository(new Zend_Tool_Framework_Action_Repository());
  153. }
  154. return $this->_actionRepository;
  155. }
  156. /**
  157. * setProviderRepository()
  158. *
  159. * @param Zend_Tool_Framework_Provider_Repository $providerRepository
  160. * @return Zend_Tool_Framework_Registry
  161. */
  162. public function setProviderRepository(Zend_Tool_Framework_Provider_Repository $providerRepository)
  163. {
  164. $this->_providerRepository = $providerRepository;
  165. if ($this->isObjectRegistryEnablable($this->_providerRepository)) {
  166. $this->enableRegistryOnObject($this->_providerRepository);
  167. }
  168. return $this;
  169. }
  170. /**
  171. * getProviderRepository()
  172. *
  173. * @return Zend_Tool_Framework_Provider_Repository
  174. */
  175. public function getProviderRepository()
  176. {
  177. if ($this->_providerRepository == null) {
  178. require_once 'Zend/Tool/Framework/Provider/Repository.php';
  179. $this->setProviderRepository(new Zend_Tool_Framework_Provider_Repository());
  180. }
  181. return $this->_providerRepository;
  182. }
  183. /**
  184. * setManifestRepository()
  185. *
  186. * @param Zend_Tool_Framework_Manifest_Repository $manifestRepository
  187. * @return Zend_Tool_Framework_Registry
  188. */
  189. public function setManifestRepository(Zend_Tool_Framework_Manifest_Repository $manifestRepository)
  190. {
  191. $this->_manifestRepository = $manifestRepository;
  192. if ($this->isObjectRegistryEnablable($this->_manifestRepository)) {
  193. $this->enableRegistryOnObject($this->_manifestRepository);
  194. }
  195. return $this;
  196. }
  197. /**
  198. * getManifestRepository()
  199. *
  200. * @return Zend_Tool_Framework_Manifest_Repository
  201. */
  202. public function getManifestRepository()
  203. {
  204. if ($this->_manifestRepository == null) {
  205. require_once 'Zend/Tool/Framework/Manifest/Repository.php';
  206. $this->setManifestRepository(new Zend_Tool_Framework_Manifest_Repository());
  207. }
  208. return $this->_manifestRepository;
  209. }
  210. /**
  211. * setRequest()
  212. *
  213. * @param Zend_Tool_Framework_Client_Request $request
  214. * @return Zend_Tool_Framework_Registry
  215. */
  216. public function setRequest(Zend_Tool_Framework_Client_Request $request)
  217. {
  218. $this->_request = $request;
  219. return $this;
  220. }
  221. /**
  222. * getRequest()
  223. *
  224. * @return Zend_Tool_Framework_Client_Request
  225. */
  226. public function getRequest()
  227. {
  228. if ($this->_request == null) {
  229. require_once 'Zend/Tool/Framework/Client/Request.php';
  230. $this->setRequest(new Zend_Tool_Framework_Client_Request());
  231. }
  232. return $this->_request;
  233. }
  234. /**
  235. * setResponse()
  236. *
  237. * @param Zend_Tool_Framework_Client_Response $response
  238. * @return Zend_Tool_Framework_Registry
  239. */
  240. public function setResponse(Zend_Tool_Framework_Client_Response $response)
  241. {
  242. $this->_response = $response;
  243. return $this;
  244. }
  245. /**
  246. * getResponse()
  247. *
  248. * @return Zend_Tool_Framework_Client_Response
  249. */
  250. public function getResponse()
  251. {
  252. if ($this->_response == null) {
  253. require_once 'Zend/Tool/Framework/Client/Response.php';
  254. $this->setResponse(new Zend_Tool_Framework_Client_Response());
  255. }
  256. return $this->_response;
  257. }
  258. /**
  259. * __get() - Get a property via property call $registry->foo
  260. *
  261. * @param string $name
  262. * @return mixed
  263. */
  264. public function __get($name)
  265. {
  266. if (method_exists($this, 'get' . $name)) {
  267. return $this->{'get' . $name}();
  268. } else {
  269. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  270. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
  271. }
  272. }
  273. /**
  274. * __set() - Set a property via the magic set $registry->foo = 'foo'
  275. *
  276. * @param string $name
  277. * @param mixed $value
  278. */
  279. public function __set($name, $value)
  280. {
  281. if (method_exists($this, 'set' . $name)) {
  282. $this->{'set' . $name}($value);
  283. return;
  284. } else {
  285. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  286. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
  287. }
  288. }
  289. /**
  290. * isObjectRegistryEnablable() - Check whether an object is registry enablable
  291. *
  292. * @param object $object
  293. * @return bool
  294. */
  295. public function isObjectRegistryEnablable($object)
  296. {
  297. if (!is_object($object)) {
  298. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  299. throw new Zend_Tool_Framework_Registry_Exception('isObjectRegistryEnablable() expects an object.');
  300. }
  301. return ($object instanceof Zend_Tool_Framework_Registry_EnabledInterface);
  302. }
  303. /**
  304. * enableRegistryOnObject() - make an object registry enabled
  305. *
  306. * @param object $object
  307. * @return Zend_Tool_Framework_Registry
  308. */
  309. public function enableRegistryOnObject($object)
  310. {
  311. if (!$this->isObjectRegistryEnablable($object)) {
  312. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  313. throw new Zend_Tool_Framework_Registry_Exception('Object provided is not registry enablable, check first with Zend_Tool_Framework_Registry::isObjectRegistryEnablable()');
  314. }
  315. $object->setRegistry($this);
  316. return $this;
  317. }
  318. }