PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/library/Zend/ModuleManager/Listener/ListenerOptions.php

https://bitbucket.org/aboozar/zf2
PHP | 276 lines | 123 code | 25 blank | 128 comment | 10 complexity | e398974666b7b8ae086e6a5cbfa1b9e3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_ModuleManager
  9. */
  10. namespace Zend\ModuleManager\Listener;
  11. use Traversable;
  12. use Zend\Stdlib\AbstractOptions;
  13. /**
  14. * Listener options
  15. *
  16. * @category Zend
  17. * @package Zend_ModuleManager
  18. * @subpackage Listener
  19. */
  20. class ListenerOptions extends AbstractOptions
  21. {
  22. /**
  23. * @var array
  24. */
  25. protected $modulePaths = array();
  26. /**
  27. * @var array
  28. */
  29. protected $configGlobPaths = array();
  30. /**
  31. * @var array
  32. */
  33. protected $configStaticPaths = array();
  34. /**
  35. * @var array
  36. */
  37. protected $extraConfig = array();
  38. /**
  39. * @var bool
  40. */
  41. protected $configCacheEnabled = false;
  42. /**
  43. * @var string
  44. */
  45. protected $configCacheKey;
  46. /**
  47. * @var string
  48. */
  49. protected $cacheDir;
  50. /**
  51. * Get an array of paths where modules reside
  52. *
  53. * @return array
  54. */
  55. public function getModulePaths()
  56. {
  57. return $this->modulePaths;
  58. }
  59. /**
  60. * Set an array of paths where modules reside
  61. *
  62. * @param array|Traversable $modulePaths
  63. * @return ListenerOptions
  64. */
  65. public function setModulePaths($modulePaths)
  66. {
  67. if (!is_array($modulePaths) && !$modulePaths instanceof Traversable) {
  68. throw new Exception\InvalidArgumentException(
  69. sprintf('Argument passed to %s::%s() must be an array, '
  70. . 'implement the \Traversable interface, or be an '
  71. . 'instance of Zend\Config\Config. %s given.',
  72. __CLASS__, __METHOD__, gettype($modulePaths))
  73. );
  74. }
  75. $this->modulePaths = $modulePaths;
  76. return $this;
  77. }
  78. /**
  79. * Get the glob patterns to load additional config files
  80. *
  81. * @return array
  82. */
  83. public function getConfigGlobPaths()
  84. {
  85. return $this->configGlobPaths;
  86. }
  87. /**
  88. * Get the static paths to load additional config files
  89. *
  90. * @return array
  91. */
  92. public function getConfigStaticPaths()
  93. {
  94. return $this->configStaticPaths;
  95. }
  96. /**
  97. * Set the glob patterns to use for loading additional config files
  98. *
  99. * @param array|Traversable $configGlobPaths
  100. * @return ListenerOptions
  101. */
  102. public function setConfigGlobPaths($configGlobPaths)
  103. {
  104. if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable) {
  105. throw new Exception\InvalidArgumentException(
  106. sprintf('Argument passed to %s::%s() must be an array, '
  107. . 'implement the \Traversable interface, or be an '
  108. . 'instance of Zend\Config\Config. %s given.',
  109. __CLASS__, __METHOD__, gettype($configGlobPaths))
  110. );
  111. }
  112. $this->configGlobPaths = $configGlobPaths;
  113. return $this;
  114. }
  115. /**
  116. * Set the static paths to use for loading additional config files
  117. *
  118. * @param array|Traversable $configStaticPaths
  119. * @return ListenerOptions
  120. */
  121. public function setConfigStaticPaths($configStaticPaths)
  122. {
  123. if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable) {
  124. throw new Exception\InvalidArgumentException(
  125. sprintf('Argument passed to %s::%s() must be an array, '
  126. . 'implement the \Traversable interface, or be an '
  127. . 'instance of Zend\Config\Config. %s given.',
  128. __CLASS__, __METHOD__, gettype($configStaticPaths))
  129. );
  130. }
  131. $this->configStaticPaths = $configStaticPaths;
  132. return $this;
  133. }
  134. /**
  135. * Get any extra config to merge in.
  136. *
  137. * @return array|Traversable
  138. */
  139. public function getExtraConfig()
  140. {
  141. return $this->extraConfig;
  142. }
  143. /**
  144. * Add some extra config array to the main config. This is mainly useful
  145. * for unit testing purposes.
  146. *
  147. * @param array|Traversable $extraConfig
  148. * @return ListenerOptions
  149. */
  150. public function setExtraConfig($extraConfig)
  151. {
  152. if (!is_array($extraConfig) && !$extraConfig instanceof Traversable) {
  153. throw new Exception\InvalidArgumentException(
  154. sprintf('Argument passed to %s::%s() must be an array, '
  155. . 'implement the \Traversable interface, or be an '
  156. . 'instance of Zend\Config\Config. %s given.',
  157. __CLASS__, __METHOD__, gettype($extraConfig))
  158. );
  159. }
  160. $this->extraConfig = $extraConfig;
  161. return $this;
  162. }
  163. /**
  164. * Check if the config cache is enabled
  165. *
  166. * @return bool
  167. */
  168. public function getConfigCacheEnabled()
  169. {
  170. return $this->configCacheEnabled;
  171. }
  172. /**
  173. * Set if the config cache should be enabled or not
  174. *
  175. * @param bool $enabled
  176. * @return ListenerOptions
  177. */
  178. public function setConfigCacheEnabled($enabled)
  179. {
  180. $this->configCacheEnabled = (bool) $enabled;
  181. return $this;
  182. }
  183. /**
  184. * Get key used to create the cache file name
  185. *
  186. * @return string
  187. */
  188. public function getConfigCacheKey()
  189. {
  190. return (string) $this->configCacheKey;
  191. }
  192. /**
  193. * Set key used to create the cache file name
  194. *
  195. * @param string $configCacheKey the value to be set
  196. * @return ListenerOptions
  197. */
  198. public function setConfigCacheKey($configCacheKey)
  199. {
  200. $this->configCacheKey = $configCacheKey;
  201. return $this;
  202. }
  203. /**
  204. * Get the path to the config cache
  205. *
  206. * Should this be an option, or should the dir option include the
  207. * filename, or should it simply remain hard-coded? Thoughts?
  208. *
  209. * @return string
  210. */
  211. public function getConfigCacheFile()
  212. {
  213. return $this->getCacheDir() . '/module-config-cache.'.$this->getConfigCacheKey().'.php';
  214. }
  215. /**
  216. * Get the path where cache file(s) are stored
  217. *
  218. * @return string
  219. */
  220. public function getCacheDir()
  221. {
  222. return $this->cacheDir;
  223. }
  224. /**
  225. * Set the path where cache files can be stored
  226. *
  227. * @param string $cacheDir the value to be set
  228. * @return ListenerOptions
  229. */
  230. public function setCacheDir($cacheDir)
  231. {
  232. if (null === $cacheDir) {
  233. $this->cacheDir = $cacheDir;
  234. } else {
  235. $this->cacheDir = static::normalizePath($cacheDir);
  236. }
  237. return $this;
  238. }
  239. /**
  240. * Normalize a path for insertion in the stack
  241. *
  242. * @param string $path
  243. * @return string
  244. */
  245. public static function normalizePath($path)
  246. {
  247. $path = rtrim($path, '/');
  248. $path = rtrim($path, '\\');
  249. return $path;
  250. }
  251. }