PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/vendors/Zend/Tool/Project/Profile/Resource.php

https://bitbucket.org/negge/tlklan2
PHP | 262 lines | 102 code | 28 blank | 132 comment | 10 complexity | dc8a3e53d2c81352c93688abdeb36bb6 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, BSD-2-Clause, GPL-3.0
  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: Resource.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Profile_Resource_Container
  24. */
  25. require_once 'Zend/Tool/Project/Profile/Resource/Container.php';
  26. /**
  27. * @see Zend_Tool_Project_Context_Repository
  28. */
  29. require_once 'Zend/Tool/Project/Context/Repository.php';
  30. /**
  31. * This class is an iterator that will iterate only over enabled resources
  32. *
  33. * @category Zend
  34. * @package Zend_Tool
  35. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Tool_Project_Profile_Resource extends Zend_Tool_Project_Profile_Resource_Container
  39. {
  40. /**
  41. * @var Zend_Tool_Project_Profile
  42. */
  43. protected $_profile = null;
  44. /**
  45. * @var Zend_Tool_Project_Profile_Resource
  46. */
  47. protected $_parentResource = null;
  48. /**#@+
  49. * @var bool
  50. */
  51. protected $_deleted = false;
  52. protected $_enabled = true;
  53. /**#@-*/
  54. /**
  55. * @var Zend_Tool_Project_Context|string
  56. */
  57. protected $_context = null;
  58. /**
  59. * @var array
  60. */
  61. protected $_attributes = array();
  62. /**
  63. * @var bool
  64. */
  65. protected $_isContextInitialized = false;
  66. /**
  67. * __construct()
  68. *
  69. * @param string|Zend_Tool_Project_Context_Interface $context
  70. */
  71. public function __construct($context)
  72. {
  73. $this->setContext($context);
  74. }
  75. /**
  76. * setContext()
  77. *
  78. * @param string|Zend_Tool_Project_Context_Interface $context
  79. * @return Zend_Tool_Project_Profile_Resource
  80. */
  81. public function setContext($context)
  82. {
  83. $this->_context = $context;
  84. return $this;
  85. }
  86. /**
  87. * getContext()
  88. *
  89. * @return Zend_Tool_Project_Context_Interface
  90. */
  91. public function getContext()
  92. {
  93. return $this->_context;
  94. }
  95. /**
  96. * getName() - Get the resource name
  97. *
  98. * Name is derived from the context name
  99. *
  100. * @return string
  101. */
  102. public function getName()
  103. {
  104. if (is_string($this->_context)) {
  105. return $this->_context;
  106. } elseif ($this->_context instanceof Zend_Tool_Project_Context_Interface) {
  107. return $this->_context->getName();
  108. } else {
  109. throw new Zend_Tool_Project_Exception('Invalid context in resource');
  110. }
  111. }
  112. /**
  113. * setProfile()
  114. *
  115. * @param Zend_Tool_Project_Profile $profile
  116. * @return Zend_Tool_Project_Profile_Resource
  117. */
  118. public function setProfile(Zend_Tool_Project_Profile $profile)
  119. {
  120. $this->_profile = $profile;
  121. return $this;
  122. }
  123. /**
  124. * getProfile
  125. *
  126. * @return Zend_Tool_Project_Profile
  127. */
  128. public function getProfile()
  129. {
  130. return $this->_profile;
  131. }
  132. /**
  133. * getPersistentAttributes()
  134. *
  135. * @return array
  136. */
  137. public function getPersistentAttributes()
  138. {
  139. if (method_exists($this->_context, 'getPersistentAttributes')) {
  140. return $this->_context->getPersistentAttributes();
  141. }
  142. return array();
  143. }
  144. /**
  145. * setEnabled()
  146. *
  147. * @param bool $enabled
  148. * @return Zend_Tool_Project_Profile_Resource
  149. */
  150. public function setEnabled($enabled = true)
  151. {
  152. // convert fuzzy types to bool
  153. $this->_enabled = (!in_array($enabled, array('false', 'disabled', 0, -1, false), true)) ? true : false;
  154. return $this;
  155. }
  156. /**
  157. * isEnabled()
  158. *
  159. * @return bool
  160. */
  161. public function isEnabled()
  162. {
  163. return $this->_enabled;
  164. }
  165. /**
  166. * setDeleted()
  167. *
  168. * @param bool $deleted
  169. * @return Zend_Tool_Project_Profile_Resource
  170. */
  171. public function setDeleted($deleted = true)
  172. {
  173. $this->_deleted = (bool) $deleted;
  174. return $this;
  175. }
  176. /**
  177. * isDeleted()
  178. *
  179. * @return Zend_Tool_Project_Profile_Resource
  180. */
  181. public function isDeleted()
  182. {
  183. return $this->_deleted;
  184. }
  185. /**
  186. * initializeContext()
  187. *
  188. * @return Zend_Tool_Project_Profile_Resource
  189. */
  190. public function initializeContext()
  191. {
  192. if ($this->_isContextInitialized) {
  193. return;
  194. }
  195. if (is_string($this->_context)) {
  196. $this->_context = Zend_Tool_Project_Context_Repository::getInstance()->getContext($this->_context);
  197. }
  198. if (method_exists($this->_context, 'setResource')) {
  199. $this->_context->setResource($this);
  200. }
  201. if (method_exists($this->_context, 'init')) {
  202. $this->_context->init();
  203. }
  204. $this->_isContextInitialized = true;
  205. return $this;
  206. }
  207. /**
  208. * __toString()
  209. *
  210. * @return string
  211. */
  212. public function __toString()
  213. {
  214. return $this->_context->getName();
  215. }
  216. /**
  217. * __call()
  218. *
  219. * @param string $method
  220. * @param array $arguments
  221. * @return Zend_Tool_Project_Profile_Resource
  222. */
  223. public function __call($method, $arguments)
  224. {
  225. if (method_exists($this->_context, $method)) {
  226. if (!$this->isEnabled()) {
  227. $this->setEnabled(true);
  228. }
  229. return call_user_func_array(array($this->_context, $method), $arguments);
  230. } else {
  231. throw new Zend_Tool_Project_Profile_Exception('cannot call ' . $method);
  232. }
  233. }
  234. }