Registry.php 11 KB

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