PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Zend/Tool/Framework/Registry.php

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