Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 30 deletions.
27 changes: 27 additions & 0 deletions src/Feature/FilterProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ModuleManager
*/

namespace Zend\ModuleManager\Feature;

/**
* @category Zend
* @package Zend_ModuleManager
* @subpackage Feature
*/
interface FilterProviderInterface
{
/**
* Expected to return \Zend\ServiceManager\Config object or array to
* seed such an object.
*
* @return array|\Zend\ServiceManager\Config
*/
public function getFilterConfig();
}
27 changes: 27 additions & 0 deletions src/Feature/ValidatorProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ModuleManager
*/

namespace Zend\ModuleManager\Feature;

/**
* @category Zend
* @package Zend_ModuleManager
* @subpackage Feature
*/
interface ValidatorProviderInterface
{
/**
* Expected to return \Zend\ServiceManager\Config object or array to
* seed such an object.
*
* @return array|\Zend\ServiceManager\Config
*/
public function getValidatorConfig();
}
22 changes: 6 additions & 16 deletions src/Listener/ConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ public function onLoadModulesPost(ModuleEvent $e)
}

// If enabled, update the config cache
if ($this->getOptions()->getConfigCacheEnabled()) {
$this->updateCache();
if (
$this->getOptions()->getConfigCacheEnabled()
&& false === $this->skipConfig
) {
$configFile = $this->getOptions()->getConfigCacheFile();
$this->writeArrayToFile($configFile, $this->getMergedConfig(false));
}

return $this;
Expand Down Expand Up @@ -392,18 +396,4 @@ protected function getCachedConfig()
{
return include $this->getOptions()->getConfigCacheFile();
}

/**
* @return ConfigListener
*/
protected function updateCache()
{
if (($this->getOptions()->getConfigCacheEnabled())
&& (false === $this->skipConfig)
) {
$configFile = $this->getOptions()->getConfigCacheFile();
$this->writeArrayToFile($configFile, $this->getMergedConfig(false));
}
return $this;
}
}
4 changes: 1 addition & 3 deletions src/Listener/DefaultListenerAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Loader\ModuleAutoloader;
use Zend\ModuleManager\ModuleEvent;
use Zend\Stdlib\CallbackHandler;

Expand Down Expand Up @@ -47,10 +46,9 @@ public function attach(EventManagerInterface $events)
$options = $this->getOptions();
$configListener = $this->getConfigListener();
$locatorRegistrationListener = new LocatorRegistrationListener($options);
$moduleAutoloader = new ModuleAutoloader($options->getModulePaths());

// High priority, we assume module autoloading (for FooNamespace\Module classes) should be available before anything else
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($moduleAutoloader, 'register'), 9000);
$this->listeners[] = $events->attach(new ModuleLoaderListener($options));
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener);
// High priority, because most other loadModule listeners will assume the module's classes are available via autoloading
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new AutoloaderListener($options), 9000);
Expand Down
76 changes: 72 additions & 4 deletions src/Listener/ListenerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class ListenerOptions extends AbstractOptions
*/
protected $cacheDir;

/**
* @var string
*/
protected $moduleMapCacheEnabled = false;

/**
* @var string
*/
protected $moduleMapCacheKey;

/**
* Get an array of paths where modules reside
*
Expand All @@ -72,7 +82,7 @@ public function getModulePaths()
*
* @param array|Traversable $modulePaths
* @throws Exception\InvalidArgumentException
* @return ListenerOptions
* @return ListenerOptions Provides fluent interface
*/
public function setModulePaths($modulePaths)
{
Expand All @@ -84,6 +94,7 @@ public function setModulePaths($modulePaths)
__CLASS__, __METHOD__, gettype($modulePaths))
);
}

$this->modulePaths = $modulePaths;
return $this;
}
Expand Down Expand Up @@ -113,7 +124,7 @@ public function getConfigStaticPaths()
*
* @param array|Traversable $configGlobPaths
* @throws Exception\InvalidArgumentException
* @return ListenerOptions
* @return ListenerOptions Provides fluent interface
*/
public function setConfigGlobPaths($configGlobPaths)
{
Expand All @@ -125,6 +136,7 @@ public function setConfigGlobPaths($configGlobPaths)
__CLASS__, __METHOD__, gettype($configGlobPaths))
);
}

$this->configGlobPaths = $configGlobPaths;
return $this;
}
Expand All @@ -134,7 +146,7 @@ public function setConfigGlobPaths($configGlobPaths)
*
* @param array|Traversable $configStaticPaths
* @throws Exception\InvalidArgumentException
* @return ListenerOptions
* @return ListenerOptions Provides fluent interface
*/
public function setConfigStaticPaths($configStaticPaths)
{
Expand All @@ -146,6 +158,7 @@ public function setConfigStaticPaths($configStaticPaths)
__CLASS__, __METHOD__, gettype($configStaticPaths))
);
}

$this->configStaticPaths = $configStaticPaths;
return $this;
}
Expand All @@ -166,7 +179,7 @@ public function getExtraConfig()
*
* @param array|Traversable $extraConfig
* @throws Exception\InvalidArgumentException
* @return ListenerOptions
* @return ListenerOptions Provides fluent interface
*/
public function setExtraConfig($extraConfig)
{
Expand All @@ -178,6 +191,7 @@ public function setExtraConfig($extraConfig)
__CLASS__, __METHOD__, gettype($extraConfig))
);
}

$this->extraConfig = $extraConfig;
return $this;
}
Expand Down Expand Up @@ -265,6 +279,60 @@ public function setCacheDir($cacheDir)
return $this;
}

/**
* Check if the module class map cache is enabled
*
* @return bool
*/
public function getModuleMapCacheEnabled()
{
return $this->moduleMapCacheEnabled;
}

/**
* Set if the module class map cache should be enabled or not
*
* @param bool $enabled
* @return ListenerOptions
*/
public function setModuleMapCacheEnabled($enabled)
{
$this->moduleMapCacheEnabled = (bool) $enabled;
return $this;
}

/**
* Get key used to create the cache file name
*
* @return string
*/
public function getModuleMapCacheKey()
{
return (string) $this->moduleMapCacheKey;
}

/**
* Set key used to create the cache file name
*
* @param string $moduleMapCacheKey the value to be set
* @return ListenerOptions
*/
public function setModuleMapCacheKey($moduleMapCacheKey)
{
$this->moduleMapCacheKey = $moduleMapCacheKey;
return $this;
}

/**
* Get the path to the module class map cache
*
* @return string
*/
public function getModuleMapCacheFile()
{
return $this->getCacheDir() . '/module-classmap-cache.'.$this->getModuleMapCacheKey().'.php';
}

/**
* Normalize a path for insertion in the stack
*
Expand Down
6 changes: 3 additions & 3 deletions src/Listener/LocatorRegistrationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function onLoadModule(ModuleEvent $e)
}

/**
* loadModulesPost
* loadModules
*
* Once all the modules are loaded, loop
*
* @param Event $e
* @return void
*/
public function onLoadModulesPost(Event $e)
public function onLoadModules(Event $e)
{
$moduleManager = $e->getTarget();
$events = $moduleManager->getEventManager()->getSharedManager();
Expand Down Expand Up @@ -122,7 +122,7 @@ public function onBootstrap(Event $e)
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'onLoadModule'));
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModulesPost'), -1000);
$this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModules'), -1000);
return $this;
}

Expand Down
Loading

0 comments on commit 42ea501

Please sign in to comment.