PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/pcelta/zf2
PHP | 280 lines | 123 code | 25 blank | 132 comment | 10 complexity | f7d0bf9bd09e3489e62b98b92ca3f4d2 MD5 | raw file
  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. * @throws Exception\InvalidArgumentException
  64. * @return ListenerOptions
  65. */
  66. public function setModulePaths($modulePaths)
  67. {
  68. if (!is_array($modulePaths) && !$modulePaths instanceof Traversable) {
  69. throw new Exception\InvalidArgumentException(
  70. sprintf('Argument passed to %s::%s() must be an array, '
  71. . 'implement the \Traversable interface, or be an '
  72. . 'instance of Zend\Config\Config. %s given.',
  73. __CLASS__, __METHOD__, gettype($modulePaths))
  74. );
  75. }
  76. $this->modulePaths = $modulePaths;
  77. return $this;
  78. }
  79. /**
  80. * Get the glob patterns to load additional config files
  81. *
  82. * @return array
  83. */
  84. public function getConfigGlobPaths()
  85. {
  86. return $this->configGlobPaths;
  87. }
  88. /**
  89. * Get the static paths to load additional config files
  90. *
  91. * @return array
  92. */
  93. public function getConfigStaticPaths()
  94. {
  95. return $this->configStaticPaths;
  96. }
  97. /**
  98. * Set the glob patterns to use for loading additional config files
  99. *
  100. * @param array|Traversable $configGlobPaths
  101. * @throws Exception\InvalidArgumentException
  102. * @return ListenerOptions
  103. */
  104. public function setConfigGlobPaths($configGlobPaths)
  105. {
  106. if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable) {
  107. throw new Exception\InvalidArgumentException(
  108. sprintf('Argument passed to %s::%s() must be an array, '
  109. . 'implement the \Traversable interface, or be an '
  110. . 'instance of Zend\Config\Config. %s given.',
  111. __CLASS__, __METHOD__, gettype($configGlobPaths))
  112. );
  113. }
  114. $this->configGlobPaths = $configGlobPaths;
  115. return $this;
  116. }
  117. /**
  118. * Set the static paths to use for loading additional config files
  119. *
  120. * @param array|Traversable $configStaticPaths
  121. * @throws Exception\InvalidArgumentException
  122. * @return ListenerOptions
  123. */
  124. public function setConfigStaticPaths($configStaticPaths)
  125. {
  126. if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable) {
  127. throw new Exception\InvalidArgumentException(
  128. sprintf('Argument passed to %s::%s() must be an array, '
  129. . 'implement the \Traversable interface, or be an '
  130. . 'instance of Zend\Config\Config. %s given.',
  131. __CLASS__, __METHOD__, gettype($configStaticPaths))
  132. );
  133. }
  134. $this->configStaticPaths = $configStaticPaths;
  135. return $this;
  136. }
  137. /**
  138. * Get any extra config to merge in.
  139. *
  140. * @return array|Traversable
  141. */
  142. public function getExtraConfig()
  143. {
  144. return $this->extraConfig;
  145. }
  146. /**
  147. * Add some extra config array to the main config. This is mainly useful
  148. * for unit testing purposes.
  149. *
  150. * @param array|Traversable $extraConfig
  151. * @throws Exception\InvalidArgumentException
  152. * @return ListenerOptions
  153. */
  154. public function setExtraConfig($extraConfig)
  155. {
  156. if (!is_array($extraConfig) && !$extraConfig instanceof Traversable) {
  157. throw new Exception\InvalidArgumentException(
  158. sprintf('Argument passed to %s::%s() must be an array, '
  159. . 'implement the \Traversable interface, or be an '
  160. . 'instance of Zend\Config\Config. %s given.',
  161. __CLASS__, __METHOD__, gettype($extraConfig))
  162. );
  163. }
  164. $this->extraConfig = $extraConfig;
  165. return $this;
  166. }
  167. /**
  168. * Check if the config cache is enabled
  169. *
  170. * @return bool
  171. */
  172. public function getConfigCacheEnabled()
  173. {
  174. return $this->configCacheEnabled;
  175. }
  176. /**
  177. * Set if the config cache should be enabled or not
  178. *
  179. * @param bool $enabled
  180. * @return ListenerOptions
  181. */
  182. public function setConfigCacheEnabled($enabled)
  183. {
  184. $this->configCacheEnabled = (bool) $enabled;
  185. return $this;
  186. }
  187. /**
  188. * Get key used to create the cache file name
  189. *
  190. * @return string
  191. */
  192. public function getConfigCacheKey()
  193. {
  194. return (string) $this->configCacheKey;
  195. }
  196. /**
  197. * Set key used to create the cache file name
  198. *
  199. * @param string $configCacheKey the value to be set
  200. * @return ListenerOptions
  201. */
  202. public function setConfigCacheKey($configCacheKey)
  203. {
  204. $this->configCacheKey = $configCacheKey;
  205. return $this;
  206. }
  207. /**
  208. * Get the path to the config cache
  209. *
  210. * Should this be an option, or should the dir option include the
  211. * filename, or should it simply remain hard-coded? Thoughts?
  212. *
  213. * @return string
  214. */
  215. public function getConfigCacheFile()
  216. {
  217. return $this->getCacheDir() . '/module-config-cache.' . $this->getConfigCacheKey().'.php';
  218. }
  219. /**
  220. * Get the path where cache file(s) are stored
  221. *
  222. * @return string
  223. */
  224. public function getCacheDir()
  225. {
  226. return $this->cacheDir;
  227. }
  228. /**
  229. * Set the path where cache files can be stored
  230. *
  231. * @param string $cacheDir the value to be set
  232. * @return ListenerOptions
  233. */
  234. public function setCacheDir($cacheDir)
  235. {
  236. if (null === $cacheDir) {
  237. $this->cacheDir = $cacheDir;
  238. } else {
  239. $this->cacheDir = static::normalizePath($cacheDir);
  240. }
  241. return $this;
  242. }
  243. /**
  244. * Normalize a path for insertion in the stack
  245. *
  246. * @param string $path
  247. * @return string
  248. */
  249. public static function normalizePath($path)
  250. {
  251. $path = rtrim($path, '/');
  252. $path = rtrim($path, '\\');
  253. return $path;
  254. }
  255. }