Skip to content

Commit

Permalink
Allow additional Mvc Rendering Strategies to be registered via config…
Browse files Browse the repository at this point in the history
…uration.
  • Loading branch information
SocalNick committed May 29, 2012
1 parent 8f5dccf commit b38dd3b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions library/Zend/Mvc/View/ViewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function onBootstrap($event)
$injectTemplateListener = new InjectTemplateListener();
$injectViewModelListener = new InjectViewModelListener();

$this->registerMvcRenderingStrategies($events);
$this->registerViewStrategies();

$events->attach($routeNotFoundStrategy);
Expand Down Expand Up @@ -460,6 +461,38 @@ public function getViewModel()
return $this->viewModel;
}

/**
* Register additional mvc rendering strategies
*
* If there is a "mvc_strategies" key of the view manager configuration, loop
* through it. Pull each as a service fromt the service manager, and, if it
* is a ListenerAggregate, pass $events to it's attach method.
*/
protected function registerMvcRenderingStrategies(EventManagerInterface $events)
{
if (!isset($this->config['mvc_strategies'])) {
return;
}
$mvcStrategies = $this->config['mvc_strategies'];
if (is_string($mvcStrategies)) {
$mvcStrategies = array($mvcStrategies);
}
if (!is_array($mvcStrategies) && !$mvcStrategies instanceof Traversable) {
return;
}

foreach ($mvcStrategies as $mvcStrategy) {
if (!is_string($mvcStrategy)) {
continue;
}

$listener = $this->services->get($mvcStrategy);
if ($listener instanceof ListenerAggregateInterface) {
$listener->attach($events);
}
}
}

/**
* Register additional view strategies
*
Expand Down

0 comments on commit b38dd3b

Please sign in to comment.