PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/alexandretaz/maniac_divers
PHP | 372 lines | 157 code | 40 blank | 175 comment | 10 complexity | 6adf98da23d7b225c6844aabffa22579 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-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\ModuleManager\Listener;
  10. use Traversable;
  11. use Zend\Stdlib\AbstractOptions;
  12. /**
  13. * Listener options
  14. */
  15. class ListenerOptions extends AbstractOptions
  16. {
  17. /**
  18. * @var array
  19. */
  20. protected $modulePaths = array();
  21. /**
  22. * @var array
  23. */
  24. protected $configGlobPaths = array();
  25. /**
  26. * @var array
  27. */
  28. protected $configStaticPaths = array();
  29. /**
  30. * @var array
  31. */
  32. protected $extraConfig = array();
  33. /**
  34. * @var bool
  35. */
  36. protected $configCacheEnabled = false;
  37. /**
  38. * @var string
  39. */
  40. protected $configCacheKey;
  41. /**
  42. * @var string
  43. */
  44. protected $cacheDir;
  45. /**
  46. * @var bool
  47. */
  48. protected $checkDependencies = true;
  49. /**
  50. * @var string
  51. */
  52. protected $moduleMapCacheEnabled = false;
  53. /**
  54. * @var string
  55. */
  56. protected $moduleMapCacheKey;
  57. /**
  58. * Get an array of paths where modules reside
  59. *
  60. * @return array
  61. */
  62. public function getModulePaths()
  63. {
  64. return $this->modulePaths;
  65. }
  66. /**
  67. * Set an array of paths where modules reside
  68. *
  69. * @param array|Traversable $modulePaths
  70. * @throws Exception\InvalidArgumentException
  71. * @return ListenerOptions Provides fluent interface
  72. */
  73. public function setModulePaths($modulePaths)
  74. {
  75. if (!is_array($modulePaths) && !$modulePaths instanceof Traversable) {
  76. throw new Exception\InvalidArgumentException(
  77. sprintf('Argument passed to %s::%s() must be an array, '
  78. . 'implement the \Traversable interface, or be an '
  79. . 'instance of Zend\Config\Config. %s given.',
  80. __CLASS__, __METHOD__, gettype($modulePaths))
  81. );
  82. }
  83. $this->modulePaths = $modulePaths;
  84. return $this;
  85. }
  86. /**
  87. * Get the glob patterns to load additional config files
  88. *
  89. * @return array
  90. */
  91. public function getConfigGlobPaths()
  92. {
  93. return $this->configGlobPaths;
  94. }
  95. /**
  96. * Get the static paths to load additional config files
  97. *
  98. * @return array
  99. */
  100. public function getConfigStaticPaths()
  101. {
  102. return $this->configStaticPaths;
  103. }
  104. /**
  105. * Set the glob patterns to use for loading additional config files
  106. *
  107. * @param array|Traversable $configGlobPaths
  108. * @throws Exception\InvalidArgumentException
  109. * @return ListenerOptions Provides fluent interface
  110. */
  111. public function setConfigGlobPaths($configGlobPaths)
  112. {
  113. if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable) {
  114. throw new Exception\InvalidArgumentException(
  115. sprintf('Argument passed to %s::%s() must be an array, '
  116. . 'implement the \Traversable interface, or be an '
  117. . 'instance of Zend\Config\Config. %s given.',
  118. __CLASS__, __METHOD__, gettype($configGlobPaths))
  119. );
  120. }
  121. $this->configGlobPaths = $configGlobPaths;
  122. return $this;
  123. }
  124. /**
  125. * Set the static paths to use for loading additional config files
  126. *
  127. * @param array|Traversable $configStaticPaths
  128. * @throws Exception\InvalidArgumentException
  129. * @return ListenerOptions Provides fluent interface
  130. */
  131. public function setConfigStaticPaths($configStaticPaths)
  132. {
  133. if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable) {
  134. throw new Exception\InvalidArgumentException(
  135. sprintf('Argument passed to %s::%s() must be an array, '
  136. . 'implement the \Traversable interface, or be an '
  137. . 'instance of Zend\Config\Config. %s given.',
  138. __CLASS__, __METHOD__, gettype($configStaticPaths))
  139. );
  140. }
  141. $this->configStaticPaths = $configStaticPaths;
  142. return $this;
  143. }
  144. /**
  145. * Get any extra config to merge in.
  146. *
  147. * @return array|Traversable
  148. */
  149. public function getExtraConfig()
  150. {
  151. return $this->extraConfig;
  152. }
  153. /**
  154. * Add some extra config array to the main config. This is mainly useful
  155. * for unit testing purposes.
  156. *
  157. * @param array|Traversable $extraConfig
  158. * @throws Exception\InvalidArgumentException
  159. * @return ListenerOptions Provides fluent interface
  160. */
  161. public function setExtraConfig($extraConfig)
  162. {
  163. if (!is_array($extraConfig) && !$extraConfig instanceof Traversable) {
  164. throw new Exception\InvalidArgumentException(
  165. sprintf('Argument passed to %s::%s() must be an array, '
  166. . 'implement the \Traversable interface, or be an '
  167. . 'instance of Zend\Config\Config. %s given.',
  168. __CLASS__, __METHOD__, gettype($extraConfig))
  169. );
  170. }
  171. $this->extraConfig = $extraConfig;
  172. return $this;
  173. }
  174. /**
  175. * Check if the config cache is enabled
  176. *
  177. * @return bool
  178. */
  179. public function getConfigCacheEnabled()
  180. {
  181. return $this->configCacheEnabled;
  182. }
  183. /**
  184. * Set if the config cache should be enabled or not
  185. *
  186. * @param bool $enabled
  187. * @return ListenerOptions
  188. */
  189. public function setConfigCacheEnabled($enabled)
  190. {
  191. $this->configCacheEnabled = (bool) $enabled;
  192. return $this;
  193. }
  194. /**
  195. * Get key used to create the cache file name
  196. *
  197. * @return string
  198. */
  199. public function getConfigCacheKey()
  200. {
  201. return (string) $this->configCacheKey;
  202. }
  203. /**
  204. * Set key used to create the cache file name
  205. *
  206. * @param string $configCacheKey the value to be set
  207. * @return ListenerOptions
  208. */
  209. public function setConfigCacheKey($configCacheKey)
  210. {
  211. $this->configCacheKey = $configCacheKey;
  212. return $this;
  213. }
  214. /**
  215. * Get the path to the config cache
  216. *
  217. * Should this be an option, or should the dir option include the
  218. * filename, or should it simply remain hard-coded? Thoughts?
  219. *
  220. * @return string
  221. */
  222. public function getConfigCacheFile()
  223. {
  224. return $this->getCacheDir() . '/module-config-cache.' . $this->getConfigCacheKey().'.php';
  225. }
  226. /**
  227. * Get the path where cache file(s) are stored
  228. *
  229. * @return string
  230. */
  231. public function getCacheDir()
  232. {
  233. return $this->cacheDir;
  234. }
  235. /**
  236. * Set the path where cache files can be stored
  237. *
  238. * @param string $cacheDir the value to be set
  239. * @return ListenerOptions
  240. */
  241. public function setCacheDir($cacheDir)
  242. {
  243. if (null === $cacheDir) {
  244. $this->cacheDir = $cacheDir;
  245. } else {
  246. $this->cacheDir = static::normalizePath($cacheDir);
  247. }
  248. return $this;
  249. }
  250. /**
  251. * Check if the module class map cache is enabled
  252. *
  253. * @return bool
  254. */
  255. public function getModuleMapCacheEnabled()
  256. {
  257. return $this->moduleMapCacheEnabled;
  258. }
  259. /**
  260. * Set if the module class map cache should be enabled or not
  261. *
  262. * @param bool $enabled
  263. * @return ListenerOptions
  264. */
  265. public function setModuleMapCacheEnabled($enabled)
  266. {
  267. $this->moduleMapCacheEnabled = (bool) $enabled;
  268. return $this;
  269. }
  270. /**
  271. * Get key used to create the cache file name
  272. *
  273. * @return string
  274. */
  275. public function getModuleMapCacheKey()
  276. {
  277. return (string) $this->moduleMapCacheKey;
  278. }
  279. /**
  280. * Set key used to create the cache file name
  281. *
  282. * @param string $moduleMapCacheKey the value to be set
  283. * @return ListenerOptions
  284. */
  285. public function setModuleMapCacheKey($moduleMapCacheKey)
  286. {
  287. $this->moduleMapCacheKey = $moduleMapCacheKey;
  288. return $this;
  289. }
  290. /**
  291. * Get the path to the module class map cache
  292. *
  293. * @return string
  294. */
  295. public function getModuleMapCacheFile()
  296. {
  297. return $this->getCacheDir() . '/module-classmap-cache.'.$this->getModuleMapCacheKey().'.php';
  298. }
  299. /**
  300. * Set whether to check dependencies during module loading or not
  301. *
  302. * @return string
  303. */
  304. public function getCheckDependencies()
  305. {
  306. return $this->checkDependencies;
  307. }
  308. /**
  309. * Set whether to check dependencies during module loading or not
  310. *
  311. * @param bool $checkDependencies the value to be set
  312. *
  313. * @return ListenerOptions
  314. */
  315. public function setCheckDependencies($checkDependencies)
  316. {
  317. $this->checkDependencies = (bool) $checkDependencies;
  318. return $this;
  319. }
  320. /**
  321. * Normalize a path for insertion in the stack
  322. *
  323. * @param string $path
  324. * @return string
  325. */
  326. public static function normalizePath($path)
  327. {
  328. $path = rtrim($path, '/');
  329. $path = rtrim($path, '\\');
  330. return $path;
  331. }
  332. }