/** * onDispatch * * @param MvcEvent $e * @return mixed * @throws Exception\DomainException */ public function onDispatch(MvcEvent $e) { $routeMatch = $e->getRouteMatch(); if (!$routeMatch) { throw new Exception\DomainException('Missing route matches; unsure how to retrieve action'); } $action = $routeMatch->getParam('action', 'not-found'); $method = static::getMethodFromAction($action); if (!method_exists($this->_getAbstractFrontActionController(), $method)) { $method = 'notFoundAction'; } $actionResponse = $this->_getAbstractFrontActionController()->{$method}(); if ($actionResponse instanceof \Core\Web\Controller\Front\ViewModel) { $actionResponse = new ViewModel($actionResponse->getData()); } else { $actionResponse = new ViewModel(); } $actionResponse->setTemplate($this->_getTemplate($action)); $e->setResult($actionResponse); return $actionResponse; }