Skip to content

Commit

Permalink
Merge branch 'hotfix/config-listener-order' of https://github.com/Eva…
Browse files Browse the repository at this point in the history
…nDotPro/zf2 into hotfix/module-config-order
  • Loading branch information
weierophinney committed Feb 1, 2012
2 parents 5ef0cad + e998619 commit 560e267
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
84 changes: 56 additions & 28 deletions library/Zend/Module/Listener/ConfigListener.php
Expand Up @@ -57,7 +57,50 @@ public function __construct(ListenerOptions $options = null)
}
}

/**
* __invoke proxy to loadModule for easier attaching
*
* @param ModuleEvent $e
* @return ConfigListener
*/
public function __invoke(ModuleEvent $e)
{
return $this->loadModule($e);
}

/**
* Attach one or more listeners
*
* @param EventCollection $events
* @return ConfigListener
*/
public function attach(EventCollection $events)
{
$this->listeners[] = $events->attach('loadModule', array($this, 'loadModule'), 1000);
$this->listeners[] = $events->attach('loadModules.pre', array($this, 'loadModulesPre'), 9000);
$this->listeners[] = $events->attach('loadModules.post', array($this, 'loadModulesPost'), 9000);
return $this;
}

/**
* Pass self to the ModuleEvent object early so everyone has access.
*
* @param ModuleEvent $e
* @return ConfigListener
*/
public function loadModulesPre(ModuleEvent $e)
{
$e->setConfigListener($this);
return $this;
}

/**
* Merge the config for each module
*
* @param ModuleEvent $e
* @return ConfigListener
*/
public function loadModule(ModuleEvent $e)
{
if (true === $this->skipConfig) {
return;
Expand All @@ -66,18 +109,25 @@ public function __invoke(ModuleEvent $e)
if (is_callable(array($module, 'getConfig'))) {
$this->mergeModuleConfig($module);
}
return $this;
}

/**
* Attach one or more listeners
* Merge all config files matched by the given glob()s
*
* @param EventCollection $events
* @return void
* This should really only be called by the module manager.
*
* @param ModuleEvent $e
* @return ConfigListener
*/
public function attach(EventCollection $events)
public function loadModulesPost(ModuleEvent $e)
{
$this->listeners[] = $events->attach('loadModule', $this, 1000);
$this->listeners[] = $events->attach('loadModules.post', array($this, 'mergeConfigGlobPaths'), 9000);
if (true === $this->skipConfig) {
return $this;
}
foreach ($this->globPaths as $globPath) {
$this->mergeGlobPath($globPath);
}
return $this;
}

Expand Down Expand Up @@ -174,28 +224,6 @@ public function addConfigGlobPaths($globPaths)
return $this;
}

/**
* Merge all config files matched by the given glob()s
*
* This should really only be called by the module manager.
*
* @param mixed $e
* @return ConfigListener
*/
public function mergeConfigGlobPaths($e = null)
{
if (true === $this->skipConfig) {
return $this;
}
foreach ($this->globPaths as $globPath) {
$this->mergeGlobPath($globPath);
}
if ($e instanceof ModuleEvent) {
$e->setConfigListener($this);
}
return $this;
}

/**
* Merge all config files matching a glob
*
Expand Down
6 changes: 3 additions & 3 deletions tests/Zend/Module/Listener/ConfigListenerTest.php
Expand Up @@ -127,7 +127,7 @@ public function testBadConfigFileExtensionThrowsRuntimeException()
$moduleManager = $this->moduleManager;
$moduleManager->setModules(array('SomeModule'));
$moduleManager->events()->attach('loadModule', $configListener);
$moduleManager->events()->attach('loadModules.post', array($configListener, 'mergeConfigGlobPaths'), 1000);
$moduleManager->events()->attach('loadModules.post', array($configListener, 'loadModulesPost'), 1000);
$moduleManager->loadModules();
}

Expand Down Expand Up @@ -244,7 +244,7 @@ public function testConfigListenerFunctionsAsAggregateListener()
$this->assertEquals(1, count($moduleManager->events()->getEvents()));

$configListener->attach($moduleManager->events());
$this->assertEquals(3, count($moduleManager->events()->getEvents()));
$this->assertEquals(4, count($moduleManager->events()->getEvents()));

$configListener->detach($moduleManager->events());
$this->assertEquals(1, count($moduleManager->events()->getEvents()));
Expand All @@ -263,7 +263,7 @@ public function testPhpConfigFileReturningInvalidConfigRaisesException()
$moduleManager->setModules(array('SomeModule'));

$moduleManager->events()->attach('loadModule', $configListener);
$moduleManager->events()->attach('loadModules.post', array($configListener, 'mergeConfigGlobPaths'), 1000);
$moduleManager->events()->attach('loadModules.post', array($configListener, 'loadModulesPost'), 1000);

$moduleManager->loadModules();
}
Expand Down

0 comments on commit 560e267

Please sign in to comment.