Execute the request

@param  MvcEvent $e
@return mixed
@throws \Zend\Mvc\Exception\DomainException
553664
public function onDispatch( MvcEvent $event )
    {
        $this->paragraphId = (int) $this->params()
                                        ->fromRoute( 'paragraphId' );

        if ( empty( $this->paragraphId ) )
        {
            $this->paragraphId = null;
        }

        return parent::onDispatch( $event );
    }
448151
public function prerenderPage(MvcEvent $event)
    {
        $originalRequest = $event->getRequest();

        if (!$this->shouldPrerenderPage($originalRequest)) {
            return;
        }

        $event->stopPropagation(true);
        $eventManager = $this->getEventManager();

        // Trigger a pre-event (for creating a response from cache, for instance)
        $responses = $eventManager->trigger(PrerenderEvent::EVENT_PRERENDER_PRE, new PrerenderEvent($originalRequest));

        if ($responses->last() instanceof HttpResponse) {
            return $responses->last();
        }

        // Make the actual request to Prerender service
        $client    = $this->getHttpClient();
        $uri       = rtrim($this->moduleOptions->getPrerenderUrl(), '/') . '/' . $originalRequest->getUriString();
        $userAgent = $originalRequest->getHeaders()->get('User-Agent')->getFieldValue();

        $client->setUri($uri)
               ->setMethod(HttpRequest::METHOD_GET);

        $request = $client->getRequest();
        $request->getHeaders()->addHeaderLine('User-Agent', $userAgent)
                              ->addHeaderLine('Accept-Encoding', 'gzip');

        if ($prerenderToken = $this->moduleOptions->getPrerenderToken()) {
            $request->getHeaders()->addHeaderLine('X-Prerender-Token', $prerenderToken);
        }

        $response = $client->send($request);

        // Trigger a post-event (for putting in cache the response, for instance)
        $prerenderEvent = new PrerenderEvent($request, $response);
        $eventManager->trigger(PrerenderEvent::EVENT_PRERENDER_POST, $prerenderEvent);

        return $prerenderEvent->getResponse();
    }
209386
public function onDispatchError(MvcEvent $event)
    {
        // Do nothing if the result is a response object
        $result   = $event->getResult();
        $response = $event->getResponse();

        if ($result instanceof Response || ($response && ! $response instanceof HttpResponse)) {
            return;
        }

        // Common view variables
        $viewVariables = array(
           'error'      => $event->getParam('error'),
           'identity'   => $event->getParam('identity'),
        );

        switch ($event->getError()) {
            case Controller::ERROR:
                $viewVariables['controller'] = $event->getParam('controller');
                $viewVariables['action']     = $event->getParam('action');
                break;
            case Route::ERROR:
                $viewVariables['route'] = $event->getParam('route');
                break;
            case Application::ERROR_EXCEPTION:
                if (!($event->getParam('exception') instanceof UnAuthorizedException)) {
                    return;
                }

                $viewVariables['reason'] = $event->getParam('exception')->getMessage();
                $viewVariables['error']  = 'error-unauthorized';
                break;
            default:
                /*
                 * do nothing if there is no error in the event or the error
                 * does not match one of our predefined errors (we don't want
                 * our 403 template to handle other types of errors)
                 */

                return;
        }

        $model    = new ViewModel($viewVariables);
        $response = $response ?: new HttpResponse();

        $model->setTemplate($this->getTemplate());
        $event->getViewModel()->addChild($model);
        $response->setStatusCode(403);
        $event->setResponse($response);
    }
1265150
public function preDispatch(MvcEvent $e) {
		if ($this->zfcUserAuthentication ()->hasIdentity ()) {
			$userName = $this->zfcUserAuthentication ()->getIdentity ()->getUsername ();
		} else {
			$userName = 'anonymous';
		}
		$this->layout ()->setVariable ( 'dataTypes', $this->getDataTypesHandler ()->getDataTypes () );
		$this->layout ()->setVariable ( 'userName', $userName );
		$this->layout ()->setVariable ( 'action', $this->params ( 'action' ) );
		$this->layout ()->setVariable ( 'authService', $this->getFileAuthService () );
		$this->layout ()->setVariable ( 'jqueryUiTheme', $this->getJqueryUiTheme () );
		$controller = $this->params ( 'controller' );
		$controller = explode ( '\\', $controller );
		$controller = array_pop ( $controller );
		$controller = strtolower ( $controller );
		$this->layout ()->setVariable ( 'controller', $controller );
	}
821197
public function onPostRoute(MvcEvent $e)
    {
        $matches = $e->getRouteMatch();
        if (!$matches instanceof Router\RouteMatch) {
            // Can't do anything without a route match
            return;
        }
        
    	// Check for 'asset_manager' route
    	$routeName = $matches->getMatchedRouteName();
    	$routeName = explode('/', $routeName, 2);
    	$routeName = $routeName[0];
    	
    	if ($routeName !== 'asset_manager') {
    		// Not an asset request
    		return;
    	}
    	
    	// TODO: Take care of grouped assets (Merged assets)
    	//       Right now only direct access
    	
    	$serviceManager = $e->getApplication()->getServiceManager();
    	$router         = $e->getRouter();
    	$assetManager   = $serviceManager->get('AssetManager');
    	
    	$requestPath     = $e->getRequest()->getUri()->getPath();
    	$requestBasePath = $router->assemble(array(), array('name' => 'asset_manager'));
    	$requestBasePath = $requestBasePath . '/';
   
    	if (strlen($requestPath) <= strlen($requestBasePath)) {
    		// Not enough data!
    		return;
    	}
    	
    	$requestPath = substr($requestPath, strlen($requestBasePath) - 1);
    	
    	$assetPathStack = $serviceManager->get('AssetPathStack');
    	$content = $assetPathStack->resolve($requestPath);  	
    	if (!empty($content)) {
    		$response = $e->getResponse();
    		$headers  = $response->getHeaders();
    		$headers->addHeaderLine('Content-Type', MimeResolver::getMimeType($requestPath));
    		$response->setContent($content);
    		return $response;
    	}
    	
    }
1143951
public function onRoute(MvcEvent $e) {
        $matches = $e->getRouteMatch();
        $module = $matches->getParam('module');
        $controller = $matches->getParam('controller');

        if ($module && $controller && strpos($controller, '\\') === false) {
            $matches->setParam(self::ORIGINAL_CONTROLLER, $controller);
            $controllerLoader = $e->getApplication()->getServiceManager()->get('ControllerManager');
            $ctrlClass = $this->convertName($module) . '\\Middleware\\';
            $ctrlClass .= $this->convertName($controller);
            $controller = $ctrlClass;
            $matches->setParam('controller', $controller);
            $ctrlClass .= 'Action';

            if (!$controllerLoader->has($controller) && class_exists($ctrlClass)) {
                $controllerLoader->setInvokableClass($controller, $ctrlClass);
                $e->setController($controller);
                $e->setControllerClass($ctrlClass);
            }
        }
    }
797764
public function injectViewModelLayout(MvcEvent $e)
    {
        $model = $e->getResult();
        if (!Share::isOnAdmin() || !$model instanceof ViewModel){
            // - we are not on admin
            return false;
        }

        /** @var $response \Zend\Http\PhpEnvironment\Response */
        $response = $e->getResponse();
        if ($response->getStatusCode() != 400 && $response->getStatusCode() != 500) {
        	// set template prefix
        	$template = $model->getTemplate();
        	//$template = (! empty($tn)) ? $tn.'/'.$template : $template;
        	$template = 'admin'.'/'.$template;
        	$model->setTemplate($template);
        }
    }
426006
public function onDispatch(MvcEvent $e)
    {
        try {
            parent::onDispatch($e);
        } catch (\Exception $e) {
            return $this->getResponse()->setStatusCode(500)->setContent($e->__toString());
        }
    }
181107
public function checkOptions(MvcEvent $e)
    {
        $matches  = $e->getRouteMatch();
        $response = $e->getResponse();
        $request  = $e->getRequest();
        $method   = $request->getMethod();

        // test if we matched an individual resource, and then test
        // if we allow the particular request method
        if ($matches->getParam('id', false)) {
            if (!in_array($method, $this->allowedResourceMethods)) {
                $response->setStatusCode(405);
                return $response;
            }
            return;
        }

        // We matched a collection; test if we allow the particular request 
        // method
        if (!in_array($method, $this->allowedCollectionMethods)) {
            $response->setStatusCode(405);
            return $response;
        }
    }
839407
public function finishEvent(MvcEvent $event)
    {
        $matchRoute = $event->getRouteMatch();

        if (empty($matchRoute)) {
            return null;
        }

        /** @var \Rcm\EventListener\EventFinishListener $eventFinishListener */
        $eventFinishListener = $this->serviceLocator->get(
            \Rcm\EventListener\EventFinishListener::class
        );

        $return = $eventFinishListener->processRcmResponses($event);

        if (!empty($return)) {
            return $return;
        }

        return null;
    }
49123
public function onDispatch(MvcEvent $event)
    {
        /* @var $response \Zend\Http\Response */
        $response = $event->getResponse();
        if (!method_exists($response, 'getStatusCode') || $response->getStatusCode() !== 404) {
            return;
        }
        $request        = $event->getRequest();
        $serviceManager = $event->getApplication()->getServiceManager();
        $assetManager   = $serviceManager->get(__NAMESPACE__ . '\Service\AssetManager');

        if (!$assetManager->resolvesToAsset($request)) {
            return;
        }

        $response->setStatusCode(200);

        return $assetManager->setAssetOnResponse($response);
    }
387089
protected function injectContentTemplate(MvcEvent $event)
    {
        $model = $event->getResult();

        if (! $model instanceof ViewModel) {
            return $this;
        }
        if ($model->getTemplate()) {
            return $this;
        }

        $routeMatch   = $event->getRouteMatch();
        $themeName    = $this->getThemeName();
        $themeOptions = $this->getThemeOptions();

        $options = [];
        if (isset($themeOptions[static::$side])) {
            $options = $themeOptions[static::$side];
        }

        if (isset($options['templates'])) {
            $templatesPath = rtrim($options['templates'], '/') . '/';
        } else {
            $templatesPath = str_replace(
                ['{theme}', '{side}'],
                [$themeName, static::$side],
                self::DefaultTemplatesPath
            );
        }

        $controller = $event->getTarget();
        if ($controller) {
            $controller = get_class($controller);
        } else {
            $controller = $routeMatch->getParam('controller', '');
        }
        $controller = $this->deriveControllerClass($controller);
        $template = $templatesPath . $this->inflectName($controller);

        $action  = $routeMatch->getParam('action');
        if (null !== $action) {
            $template .= '/' . $this->inflectName($action);
        }

        $model->setTemplate($template);

        return $this;
    }
1213928
public function onDispatch(MvcEvent $e)
    {
        $this->routeMatch = $e->getRouteMatch();

        $preResponse = $this->preDispatch($e);

        /** @var MvcEvent $e */

        if ($preResponse !== null) {
            $e->setResult($preResponse);

            return $preResponse;
        }

        $actionResponse = parent::onDispatch($e);

        $e->setResult($actionResponse);

        $postResponse = $this->postDispatch($e);

        if ($postResponse !== null) {
            /** @var MvcEvent $e */
            $e->setResult($postResponse);
        }

        return $e->getResult();
    }
720126
public function handler(MvcEvent $event)
    {
        $match = $event->getRouteMatch();

        if (!$match) { // we need a route
            return;
        }

        $role = $this->roleProvider->getUserRole();

        if (!$this->acl->isAllowed($role, $match->getMatchedRouteName())) {
            $controller = $this->config['TrascastroACL']['forbidden']['controller'];
            $action     = $this->config['TrascastroACL']['forbidden']['action'];
            $response   = $event->getResponse();

            $response->setStatusCode(Response::STATUS_CODE_403); // Forbidden
            $match->setParam('controller', $controller);
            $match->setParam('action', $action);
        }

        // we make the acl available on views
        $event->getViewModel()->setVariable('tacl', $this->acl);
    }
446593
public function onDispatch(MvcEvent $event)
    {
        /* @var $service \BjyAuthorize\Service\Authorize */
        $service    = $this->serviceLocator->get('BjyAuthorize\Service\Authorize');
        $match      = $event->getRouteMatch();
        $controller = $match->getParam('controller');
        $action     = $match->getParam('action');
        $request    = $event->getRequest();
        $method     = $request instanceof HttpRequest ? strtolower($request->getMethod()) : null;

        $authorized = $service->isAllowed($this->getResourceName($controller))
            || $service->isAllowed($this->getResourceName($controller, $action))
            || ($method && $service->isAllowed($this->getResourceName($controller, $method)));

        if ($authorized) {
            return;
        }

        $event->setError(static::ERROR);
        $event->setParam('identity', $service->getIdentity());
        $event->setParam('controller', $controller);
        $event->setParam('action', $action);

        $errorMessage = sprintf("You are not authorized to access %s:%s", $controller, $action);
        $event->setParam('exception', new UnAuthorizedException($errorMessage));

        /* @var $app \Zend\Mvc\ApplicationInterface */
        $app = $event->getTarget();
        $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
    }
913331
public function dispatchEvent(MvcEvent $event)
    {
        /**
         * Don't do anything for assets
         */
        $matchRoute = $event->getRouteMatch();
        if (empty($matchRoute)) {
            return null;
        }

        /** @var \Rcm\EventListener\DispatchListener $dispatchListener */
        $dispatchListener
            = $this->serviceLocator->get(\Rcm\EventListener\DispatchListener::class);

        $return = $dispatchListener->setSiteLayout($event);

        if (!empty($return)) {
            return $return;
        }

        return null;
    }
19730
public function loadLayout(MvcEvent $e)
    {
        /* @var $result ModelInterface */
        $result = $e->getViewModel();
        if (!$result->terminate()) {
            $this->layout->load();
        }
    }