3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mvc\View\Console
;
12 use Zend\Console\Request
as ConsoleRequest
;
13 use Zend\EventManager\AbstractListenerAggregate
;
14 use Zend\EventManager\EventManagerInterface
as Events
;
15 use Zend\Mvc\MvcEvent
;
17 class InjectNamedConsoleParamsListener
extends AbstractListenerAggregate
22 public function attach(Events
$events)
24 $this->listeners
[] = $events->attach(MvcEvent
::EVENT_DISPATCH
, array($this, 'injectNamedParams'), -80);
28 * Inspect the result, and cast it to a ViewModel if a string is detected
33 public function injectNamedParams(MvcEvent
$e)
35 if (!$routeMatch = $e->getRouteMatch()) {
36 return; // cannot work without route match
39 $request = $e->getRequest();
40 if (!$request instanceof ConsoleRequest
) {
41 return; // will not inject non-console requests
44 // Inject route match params into request
45 $params = array_merge(
46 $request->getParams()->toArray(),
47 $routeMatch->getParams()
49 $request->getParams()->fromArray($params);