3 * Zend Framework (http://framework.zend.com/)
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
10 namespace Zend\ModuleManager\Listener
;
13 use Zend\Stdlib\AbstractOptions
;
18 class ListenerOptions
extends AbstractOptions
23 protected $modulePaths = array();
28 protected $configGlobPaths = array();
33 protected $configStaticPaths = array();
38 protected $extraConfig = array();
43 protected $configCacheEnabled = false;
48 protected $configCacheKey;
58 protected $checkDependencies = true;
63 protected $moduleMapCacheEnabled = false;
68 protected $moduleMapCacheKey;
71 * Get an array of paths where modules reside
75 public function getModulePaths()
77 return $this->modulePaths
;
81 * Set an array of paths where modules reside
83 * @param array|Traversable $modulePaths
84 * @throws Exception\InvalidArgumentException
85 * @return ListenerOptions Provides fluent interface
87 public function setModulePaths($modulePaths)
89 if (!is_array($modulePaths) && !$modulePaths instanceof Traversable
) {
90 throw new Exception\
InvalidArgumentException(
91 sprintf('Argument passed to %s::%s() must be an array, '
92 . 'implement the Traversable interface, or be an '
93 . 'instance of Zend\Config\Config. %s given.',
94 __CLASS__
, __METHOD__
, gettype($modulePaths))
98 $this->modulePaths
= $modulePaths;
103 * Get the glob patterns to load additional config files
107 public function getConfigGlobPaths()
109 return $this->configGlobPaths
;
113 * Get the static paths to load additional config files
117 public function getConfigStaticPaths()
119 return $this->configStaticPaths
;
123 * Set the glob patterns to use for loading additional config files
125 * @param array|Traversable $configGlobPaths
126 * @throws Exception\InvalidArgumentException
127 * @return ListenerOptions Provides fluent interface
129 public function setConfigGlobPaths($configGlobPaths)
131 if (!is_array($configGlobPaths) && !$configGlobPaths instanceof Traversable
) {
132 throw new Exception\
InvalidArgumentException(
133 sprintf('Argument passed to %s::%s() must be an array, '
134 . 'implement the Traversable interface, or be an '
135 . 'instance of Zend\Config\Config. %s given.',
136 __CLASS__
, __METHOD__
, gettype($configGlobPaths))
140 $this->configGlobPaths
= $configGlobPaths;
145 * Set the static paths to use for loading additional config files
147 * @param array|Traversable $configStaticPaths
148 * @throws Exception\InvalidArgumentException
149 * @return ListenerOptions Provides fluent interface
151 public function setConfigStaticPaths($configStaticPaths)
153 if (!is_array($configStaticPaths) && !$configStaticPaths instanceof Traversable
) {
154 throw new Exception\
InvalidArgumentException(
155 sprintf('Argument passed to %s::%s() must be an array, '
156 . 'implement the Traversable interface, or be an '
157 . 'instance of Zend\Config\Config. %s given.',
158 __CLASS__
, __METHOD__
, gettype($configStaticPaths))
162 $this->configStaticPaths
= $configStaticPaths;
167 * Get any extra config to merge in.
169 * @return array|Traversable
171 public function getExtraConfig()
173 return $this->extraConfig
;
177 * Add some extra config array to the main config. This is mainly useful
178 * for unit testing purposes.
180 * @param array|Traversable $extraConfig
181 * @throws Exception\InvalidArgumentException
182 * @return ListenerOptions Provides fluent interface
184 public function setExtraConfig($extraConfig)
186 if (!is_array($extraConfig) && !$extraConfig instanceof Traversable
) {
187 throw new Exception\
InvalidArgumentException(
188 sprintf('Argument passed to %s::%s() must be an array, '
189 . 'implement the Traversable interface, or be an '
190 . 'instance of Zend\Config\Config. %s given.',
191 __CLASS__
, __METHOD__
, gettype($extraConfig))
195 $this->extraConfig
= $extraConfig;
200 * Check if the config cache is enabled
204 public function getConfigCacheEnabled()
206 return $this->configCacheEnabled
;
210 * Set if the config cache should be enabled or not
212 * @param bool $enabled
213 * @return ListenerOptions
215 public function setConfigCacheEnabled($enabled)
217 $this->configCacheEnabled
= (bool) $enabled;
222 * Get key used to create the cache file name
226 public function getConfigCacheKey()
228 return (string) $this->configCacheKey
;
232 * Set key used to create the cache file name
234 * @param string $configCacheKey the value to be set
235 * @return ListenerOptions
237 public function setConfigCacheKey($configCacheKey)
239 $this->configCacheKey
= $configCacheKey;
244 * Get the path to the config cache
246 * Should this be an option, or should the dir option include the
247 * filename, or should it simply remain hard-coded? Thoughts?
251 public function getConfigCacheFile()
253 return $this->getCacheDir() . '/module-config-cache.' . $this->getConfigCacheKey().'.php';
257 * Get the path where cache file(s) are stored
261 public function getCacheDir()
263 return $this->cacheDir
;
267 * Set the path where cache files can be stored
269 * @param string $cacheDir the value to be set
270 * @return ListenerOptions
272 public function setCacheDir($cacheDir)
274 if (null === $cacheDir) {
275 $this->cacheDir
= $cacheDir;
277 $this->cacheDir
= static::normalizePath($cacheDir);
283 * Check if the module class map cache is enabled
287 public function getModuleMapCacheEnabled()
289 return $this->moduleMapCacheEnabled
;
293 * Set if the module class map cache should be enabled or not
295 * @param bool $enabled
296 * @return ListenerOptions
298 public function setModuleMapCacheEnabled($enabled)
300 $this->moduleMapCacheEnabled
= (bool) $enabled;
305 * Get key used to create the cache file name
309 public function getModuleMapCacheKey()
311 return (string) $this->moduleMapCacheKey
;
315 * Set key used to create the cache file name
317 * @param string $moduleMapCacheKey the value to be set
318 * @return ListenerOptions
320 public function setModuleMapCacheKey($moduleMapCacheKey)
322 $this->moduleMapCacheKey
= $moduleMapCacheKey;
327 * Get the path to the module class map cache
331 public function getModuleMapCacheFile()
333 return $this->getCacheDir() . '/module-classmap-cache.'.$this->getModuleMapCacheKey().'.php';
337 * Set whether to check dependencies during module loading or not
341 public function getCheckDependencies()
343 return $this->checkDependencies
;
347 * Set whether to check dependencies during module loading or not
349 * @param bool $checkDependencies the value to be set
351 * @return ListenerOptions
353 public function setCheckDependencies($checkDependencies)
355 $this->checkDependencies
= (bool) $checkDependencies;
361 * Normalize a path for insertion in the stack
363 * @param string $path
366 public static function normalizePath($path)
368 $path = rtrim($path, '/');
369 $path = rtrim($path, '\\');