Skip to content

Commit

Permalink
Added ability to configure MvcEvent listeners.
Browse files Browse the repository at this point in the history
Change-Id: I568ec78485724be3ec68c0b754d9af95b3ea1b03
  • Loading branch information
andrei-stsiapanau committed Mar 1, 2013
1 parent e09ba97 commit f7bed11
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions library/Zend/Mvc/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,22 @@ public function getConfig()
* router. Attaches the ViewManager as a listener. Triggers the bootstrap
* event.
*
* @param array $listeners List of listeners to attach.
* @return Application
*/
public function bootstrap()
public function bootstrap(array $listeners = array())
{
$serviceManager = $this->serviceManager;
$events = $this->getEventManager();

$events->attach($serviceManager->get('RouteListener'));
$events->attach($serviceManager->get('DispatchListener'));
$events->attach($serviceManager->get('ViewManager'));
$events->attach($serviceManager->get('SendResponseListener'));
if (empty($listeners)) {
$listeners = array(
'RouteListener', 'DispatchListener', 'ViewManager', 'SendReponseListener');
}

foreach ($listeners as $listener) {
$events->attach($serviceManager->get($listener));
}

// Setup MVC Event
$this->event = $event = new MvcEvent();
Expand Down Expand Up @@ -233,10 +238,11 @@ public function getEventManager()
public static function init($configuration = array())
{
$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
$listeners = isset($configuration['listeners']) ? $configuration['listeners'] : array();
$serviceManager = new ServiceManager(new Service\ServiceManagerConfig($smConfig));
$serviceManager->setService('ApplicationConfig', $configuration);
$serviceManager->get('ModuleManager')->loadModules();
return $serviceManager->get('Application')->bootstrap();
return $serviceManager->get('Application')->bootstrap($listeners);
}

/**
Expand Down

0 comments on commit f7bed11

Please sign in to comment.