Skip to content

Commit

Permalink
Attach some default listeners to the module manager
Browse files Browse the repository at this point in the history
- Attaches them lazily once the EventManager is instantiated
- Ability to disable the defaults for supplying custom listeners instead
- getMergedConfig() method in module manager that proxies through to the config
listener
  • Loading branch information
EvanDotPro committed Nov 14, 2011
1 parent 8015688 commit 2e26ddb
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion library/Zend/Module/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ class Manager
/**
* True if modules have already been loaded
*
* @var boolean
* @var bool
*/
protected $modulesLoaded = false;

/**
* If true, will not register the default config/init listeners
*
* @var bool
*/
protected $disableLoadDefaultListeners = false;

/**
* __construct
*
Expand Down Expand Up @@ -152,7 +159,44 @@ public function events()
{
if (!$this->events instanceof EventCollection) {
$this->setEventManager(new EventManager(array(__CLASS__, get_class($this))));
$this->setDefaultListeners();
}
return $this->events;
}

public function setDisableLoadDefaultListeners($flag)
{
$this->disableLoadDefaultListeners = (bool) $flag;
return $this;
}

public function loadDefaultListenersIsDisabled()
{
return $this->disableLoadDefaultListeners;
}

protected function setDefaultListeners()
{
if ($this->loadDefaultListenersIsDisabled()) {
return $this;
}
$init = new Listener\InitTrigger;
$config = new Listener\ConfigListener;
$autoload = new Listener\AutoloaderTrigger;
$this->events()->attach('loadModule', $init, 1000);
$this->events()->attach('loadModule', $config, 1000);
$this->events()->attach('loadModule', $autoload, 1000);
}

public function getMergedConfig($returnConfigAsObject = true)
{
$listeners = $this->events()->getListeners('loadModule');
foreach ($listeners as $listener) {
$listener = $listener->getCallback();
if ($listener instanceof Listener\ConfigListener) {
return $listener->getMergedConfig($returnConfigAsObject);
}
}
return false;
}
}

0 comments on commit 2e26ddb

Please sign in to comment.