PageRenderTime 23ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zend-modulemanager/src/Listener/ListenerOptions.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 396 lines | 179 code | 42 blank | 175 comment | 12 complexity | 90f8b8052ad93e2283847c6403c70b0c 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-2015 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(
  78. 'Argument passed to %s::%s() must be an array, '
  79. . 'implement the Traversable interface, or be an '
  80. . 'instance of Zend\Config\Config. %s given.',
  81. __CLASS__,
  82. __METHOD__,
  83. gettype($modulePaths)
  84. )
  85. );
  86. }
  87. $this->modulePaths = $modulePaths;
  88. return $this;
  89. }
  90. /**
  91. * Get the glob patterns to load additional config files
  92. *
  93. * @return array
  94. */
  95. public function getConfigGlobPaths()
  96. {
  97. return $this->configGlobPaths;
  98. }
  99. /**
  100. * Get the static paths to load additional config files
  101. *
  102. * @return array
  103. */
  104. public function getConfigStaticPaths()
  105. {
  106. return $this->configStaticPaths;
  107. }
  108. /**
  109. * Set the glob patterns to use for loading additional config files
  110. *
  111. * @param array|Traversable $configGlobPaths
  112. * @throws Exception\InvalidArgumentException
  113. * @return ListenerOptions Provides fluent interface
  114. */
  115. public function setConfigGlobPaths($configGlobPaths)
  116. {
  117. if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable) {
  118. throw new Exception\InvalidArgumentException(
  119. sprintf(
  120. 'Argument passed to %s::%s() must be an array, '
  121. . 'implement the Traversable interface, or be an '
  122. . 'instance of Zend\Config\Config. %s given.',
  123. __CLASS__,
  124. __METHOD__,
  125. gettype($configGlobPaths)
  126. )
  127. );
  128. }
  129. $this->configGlobPaths = $configGlobPaths;
  130. return $this;
  131. }
  132. /**
  133. * Set the static paths to use for loading additional config files
  134. *
  135. * @param array|Traversable $configStaticPaths
  136. * @throws Exception\InvalidArgumentException
  137. * @return ListenerOptions Provides fluent interface
  138. */
  139. public function setConfigStaticPaths($configStaticPaths)
  140. {
  141. if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable) {
  142. throw new Exception\InvalidArgumentException(
  143. sprintf(
  144. 'Argument passed to %s::%s() must be an array, '
  145. . 'implement the Traversable interface, or be an '
  146. . 'instance of Zend\Config\Config. %s given.',
  147. __CLASS__,
  148. __METHOD__,
  149. gettype($configStaticPaths)
  150. )
  151. );
  152. }
  153. $this->configStaticPaths = $configStaticPaths;
  154. return $this;
  155. }
  156. /**
  157. * Get any extra config to merge in.
  158. *
  159. * @return array|Traversable
  160. */
  161. public function getExtraConfig()
  162. {
  163. return $this->extraConfig;
  164. }
  165. /**
  166. * Add some extra config array to the main config. This is mainly useful
  167. * for unit testing purposes.
  168. *
  169. * @param array|Traversable $extraConfig
  170. * @throws Exception\InvalidArgumentException
  171. * @return ListenerOptions Provides fluent interface
  172. */
  173. public function setExtraConfig($extraConfig)
  174. {
  175. if (!is_array($extraConfig) && !$extraConfig instanceof Traversable) {
  176. throw new Exception\InvalidArgumentException(
  177. sprintf(
  178. 'Argument passed to %s::%s() must be an array, '
  179. . 'implement the Traversable interface, or be an '
  180. . 'instance of Zend\Config\Config. %s given.',
  181. __CLASS__,
  182. __METHOD__,
  183. gettype($extraConfig)
  184. )
  185. );
  186. }
  187. $this->extraConfig = $extraConfig;
  188. return $this;
  189. }
  190. /**
  191. * Check if the config cache is enabled
  192. *
  193. * @return bool
  194. */
  195. public function getConfigCacheEnabled()
  196. {
  197. return $this->configCacheEnabled;
  198. }
  199. /**
  200. * Set if the config cache should be enabled or not
  201. *
  202. * @param bool $enabled
  203. * @return ListenerOptions
  204. */
  205. public function setConfigCacheEnabled($enabled)
  206. {
  207. $this->configCacheEnabled = (bool) $enabled;
  208. return $this;
  209. }
  210. /**
  211. * Get key used to create the cache file name
  212. *
  213. * @return string
  214. */
  215. public function getConfigCacheKey()
  216. {
  217. return (string) $this->configCacheKey;
  218. }
  219. /**
  220. * Set key used to create the cache file name
  221. *
  222. * @param string $configCacheKey the value to be set
  223. * @return ListenerOptions
  224. */
  225. public function setConfigCacheKey($configCacheKey)
  226. {
  227. $this->configCacheKey = $configCacheKey;
  228. return $this;
  229. }
  230. /**
  231. * Get the path to the config cache
  232. *
  233. * Should this be an option, or should the dir option include the
  234. * filename, or should it simply remain hard-coded? Thoughts?
  235. *
  236. * @return string
  237. */
  238. public function getConfigCacheFile()
  239. {
  240. if ($this->getConfigCacheKey()) {
  241. return $this->getCacheDir() . '/module-config-cache.' . $this->getConfigCacheKey().'.php';
  242. }
  243. return $this->getCacheDir() . '/module-config-cache.php';
  244. }
  245. /**
  246. * Get the path where cache file(s) are stored
  247. *
  248. * @return string
  249. */
  250. public function getCacheDir()
  251. {
  252. return $this->cacheDir;
  253. }
  254. /**
  255. * Set the path where cache files can be stored
  256. *
  257. * @param string $cacheDir the value to be set
  258. * @return ListenerOptions
  259. */
  260. public function setCacheDir($cacheDir)
  261. {
  262. if (null === $cacheDir) {
  263. $this->cacheDir = $cacheDir;
  264. } else {
  265. $this->cacheDir = static::normalizePath($cacheDir);
  266. }
  267. return $this;
  268. }
  269. /**
  270. * Check if the module class map cache is enabled
  271. *
  272. * @return bool
  273. */
  274. public function getModuleMapCacheEnabled()
  275. {
  276. return $this->moduleMapCacheEnabled;
  277. }
  278. /**
  279. * Set if the module class map cache should be enabled or not
  280. *
  281. * @param bool $enabled
  282. * @return ListenerOptions
  283. */
  284. public function setModuleMapCacheEnabled($enabled)
  285. {
  286. $this->moduleMapCacheEnabled = (bool) $enabled;
  287. return $this;
  288. }
  289. /**
  290. * Get key used to create the cache file name
  291. *
  292. * @return string
  293. */
  294. public function getModuleMapCacheKey()
  295. {
  296. return (string) $this->moduleMapCacheKey;
  297. }
  298. /**
  299. * Set key used to create the cache file name
  300. *
  301. * @param string $moduleMapCacheKey the value to be set
  302. * @return ListenerOptions
  303. */
  304. public function setModuleMapCacheKey($moduleMapCacheKey)
  305. {
  306. $this->moduleMapCacheKey = $moduleMapCacheKey;
  307. return $this;
  308. }
  309. /**
  310. * Get the path to the module class map cache
  311. *
  312. * @return string
  313. */
  314. public function getModuleMapCacheFile()
  315. {
  316. if ($this->getModuleMapCacheKey()) {
  317. return $this->getCacheDir() . '/module-classmap-cache.' . $this->getModuleMapCacheKey() . '.php';
  318. }
  319. return $this->getCacheDir() . '/module-classmap-cache.php';
  320. }
  321. /**
  322. * Set whether to check dependencies during module loading or not
  323. *
  324. * @return string
  325. */
  326. public function getCheckDependencies()
  327. {
  328. return $this->checkDependencies;
  329. }
  330. /**
  331. * Set whether to check dependencies during module loading or not
  332. *
  333. * @param bool $checkDependencies the value to be set
  334. *
  335. * @return ListenerOptions
  336. */
  337. public function setCheckDependencies($checkDependencies)
  338. {
  339. $this->checkDependencies = (bool) $checkDependencies;
  340. return $this;
  341. }
  342. /**
  343. * Normalize a path for insertion in the stack
  344. *
  345. * @param string $path
  346. * @return string
  347. */
  348. public static function normalizePath($path)
  349. {
  350. $path = rtrim($path, '/');
  351. $path = rtrim($path, '\\');
  352. return $path;
  353. }
  354. }