*
@param  MvcEvent $event
@throws Exception
431500
public function error(MvcEvent $event): void
    {
        if (
            true === $this->tracyOptions->getEnabled()
            && null !== $event->getParam('error')
            && null !== $event->getParam('exception')
        ) {
            ob_clean();

            throw $event->getParam('exception');
        }
    }
560901
public function collect(MvcEvent $mvcEvent)
    {
        if (!$application = $mvcEvent->getApplication()) {
            return;
        }

        $serviceManager = $application->getServiceManager();

        /* @var \ZfcRbac\Service\RoleService $roleService */
        $roleService = $serviceManager->get('ZfcRbac\Service\RoleService');

        /* @var \ZfcRbac\Options\ModuleOptions $options */
        $options = $serviceManager->get('ZfcRbac\Options\ModuleOptions');

        // Start collect all the data we need!
        $this->collectOptions($options);
        $this->collectGuards($options->getGuards());
        $this->collectIdentityRolesAndPermissions($roleService);
    }
1200135
public function onRoute(MvcEvent $event)
    {
        /* @var $service \BjyAuthorize\Service\Authorize */
        $service    = $this->serviceLocator->get('BjyAuthorize\Service\Authorize');
        $match      = $event->getRouteMatch();
        $routeName  = $match->getMatchedRouteName();

        if ($service->isAllowed('route/' . $routeName)) {
            return;
        }

        $event->setError(static::ERROR);
        $event->setParam('route', $routeName);
        $event->setParam('identity', $service->getIdentity());
        $event->setParam('exception', new UnAuthorizedException('You are not authorized to access ' . $routeName));

        /* @var $app \Zend\Mvc\Application */
        $app = $event->getTarget();

        $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
    }
638580
public function handle($event)
    {
        if ($event instanceof CExceptionEvent)
            $this->logExceptionEvent($event);
        else
            $this->logErrorEvent($event);
        parent::handle($event);
    }
744863
public function routeLoad(MvcEvent $event)
    {
        $request = $event->getRequest();
        if(!(
            $request->getMethod() == \Zend\Http\Request::METHOD_GET &&
            $request->getQuery()->count() == 0
        )) {
            // We do not cache route match for requests that can produce
            // different match.
            return ;
        }
    
        $event->setParam('route-cacheable', true);
    
        // check if we have data in our cache
        $path = $request->getUri()
                        ->getPath();
    
        $cache = $event->getApplication()->getServiceManager()->get('var-cache');
        $cacheKey = $this->getCacheKey($path);
        $cachedData = $cache->getItem($cacheKey);
    
        if(!empty($cachedData)) {
            $event->setParam('route-cached', true);
    
            $cachedRoute = \Zend\Mvc\Router\Http\Literal::factory($cachedData);
            $router = $event->getRouter();
            $router->addRoute($cachedData['name'], $cachedRoute, 99999);
        }
    }
958919
public function detectAccessDenied(MvcEvent $event)
    {
        $response = $event->getResponse();
        if ($response->getStatusCode() == 403) {
            $event->setError('Access Denied');
            $event->stopPropagation(true);
        }
    }
154967
public function onDispatch( MvcEvent $event )
    {
        if ( $this->response )
        {
            $event->stopPropagation();
            return $this->response;
        }

        $routeMatch = $event->getRouteMatch();
        $sm         = $event->getApplication()
                            ->getServiceManager();

        // Set current timezone, when first get
        $sm->get( 'Timezone' );

        if ( $routeMatch )
        {
            $locale = $routeMatch->getParam( 'locale' );
        }

        if ( ! $locale )
        {
            $request = $event->getRequest();

            if ( $request instanceof HttpRequest )
            {
                $header = $request->getHeader( 'Accept-Language' );

                if ( $header )
                {
                    $availables = null;
                    $controller = $event->getController();

                    if ( $controller instanceof LocaleSelectorInterface )
                    {
                        $availables = $controller->getAvailableLocales();
                    }

                    $locale = $sm->get( 'Locale' )
                                 ->acceptFromHttp( $header->getFieldValue(),
                                                   $availables );
                }
            }
        }

        if ( $locale )
        {
            $sm->get( 'Locale' )
               ->setCurrent( $locale );
        }
    }
950706
protected function complete($return, MvcEvent $event)
    {
        if (!is_object($return)) {
            if (ArrayUtils::hasStringKeys($return)) {
                $return = new ArrayObject($return, ArrayObject::ARRAY_AS_PROPS);
            }
        }
        $event->setResult($return);

        return $return;
    }
1273473
public function injectMetaContent( MvcEvent $event )
    {
        $result = $event->getResult();

        if ( ! $result instanceof MetaContent )
        {
            return;
        }

        $middle         = $this->getMiddleLayoutModel();
        $paragraph      = $middle->getParagraphModel();
        $renderList     = $paragraph->findRenderList( $result->getName() );

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

        $meta = reset( $renderList )[1];

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

        $application    = $event->getApplication();
        $serviceManager = $application->getServiceManager();
        $allowOverride  = $serviceManager->getAllowOverride();

        if ( ! $allowOverride )
        {
            $serviceManager->setAllowOverride( true );
        }

        $serviceManager->setService( 'RenderedContent', $meta );

        if ( ! $allowOverride )
        {
            $serviceManager->setAllowOverride( false );
        }

        if ( $meta instanceof LayoutAwareInterface )
        {
            $event->getViewModel()
                  ->setVariable(
                        'middleLayout',
                        $middle->findMiddleParagraphLayoutById(
                            $meta->getLayoutId()
                        )
                    );
        }

        $model = new ViewModel( array(
            'paragraphRenderList' => $renderList,
        ) );

        $model->setTemplate( 'grid/paragraph/render/paragraph' );
        $model->addChild( $result, 'content' );
        $event->setResult( $model );
    }
412138
public function sendEvent(Event $event)
    {
        try {
            $this->eventFactory->addDefaultTagsToEntity($event);
            $this->sendEventThroughSenders($event);
        } catch (\Exception $exception) {
            $this->logException($exception);
        }
    }
426006
public function onDispatch(MvcEvent $e)
    {
        try {
            parent::onDispatch($e);
        } catch (\Exception $e) {
            return $this->getResponse()->setStatusCode(500)->setContent($e->__toString());
        }
    }
394213
public function init(MvcEvent $e)
    {
        $request = $e->getRequest();
        if (!$request instanceof Request) {
            return;
        }

        $sem = $e->getApplication()->getEventManager()->getSharedManager();
        $sem->attach('UploadableManager', 'createFile', [$this, 'onCreateFile']);
    }
361804
public function setUseCapture(MvcEvent $e)
    {
        if (!$e->getRequest() instanceof HttpRequest || !($options = $e->getParam('module-options'))) {
            return;
        }

        if ($options instanceof FormOptionsInterface && null === $options->getUseCaptcha()) {
            $authService = $e->getApplication()->getServiceManager()
                ->get(AuthenticationServiceInterface::class);
            $options->setUseCaptcha(!$authService->hasIdentity());
        }
    }
999946
public function prepareException(MvcEvent $e)
    {
        if ($e->getRequest() instanceof Request) {
            $error = $e->getError();
            if (!empty($error) && !$e->getResult() instanceof Response) {
                switch ($error) {
                    case Application::ERROR_CONTROLLER_NOT_FOUND:
                    case Application::ERROR_CONTROLLER_INVALID:
                    case Application::ERROR_ROUTER_NO_MATCH:
                        // Specifically not handling these
                        return;

                    case Application::ERROR_EXCEPTION:
                    default:
                        /** @var Exception $exception */
                        $exception = $e->getParam('exception');
                        // Filter exceptions that we must except
                        foreach ($this->whoopsConfig['blacklist'] as $except) {
                            if ($exception instanceof $except) {
                                return;
                            }
                        }

                        if ($this->whoopsConfig['handler']['options_type'] === 'prettyPage') {
                            $response = $e->getResponse();
                            if (!$response || $response->getStatusCode() === 200) {
                                header('HTTP/1.0 500 Internal Server Error', true, 500);
                            }
                            ob_clean();
                        }

                        $this->run->handleException($e->getParam('exception'));
                        break;
                }
            }
        }
    }
199296
public function routeSave(MvcEvent $event)
    {
        $match = $event->getRouteMatch();
        if (!$match || !$event->getRequest() instanceof HttpRequest) {
            return;
        }

        if ($event->getParam('route-cached') || !$event->getParam('route-cacheable')) {
            return;
        }

        $path = $event->getRequest()->getUri()->getPath();

        // save the route match into the cache.
        $services = $event->getApplication()->getServiceManager();

        $cacheName = $services->get(RouterCacheOptions::class)->getCache();
        $cache = $services->get($cacheName);

        $cacheKey = $this->getCacheKey($path);

        $name = $match->getMatchedRouteName();
        $data = [
            'name' => $name,
            'spec' => [
                'type' => 'Literal',
                'options' => [
                    'route' => $path,
                    'defaults' => $match->getParams(),
                ],
            ],
        ];

        $routes = $services->get('Config')['router']['routes'];
        if (isset($routes[$name])) {
            $data['spec'] = array_replace_recursive($routes[$name], $data['spec']);
        }

        $cache->setItem($cacheKey, $data);
    }
49109
protected function handle($event): void
    {
        $method = $this->getApplyMethod($event);

        if (!method_exists($this, $method)) {
            return;
        }

        $this->$method($event);
    }
421484
protected function eventsCallback(string $name, string $event): void
    {
        $this->server->on($name, function () use ($name, $event) {
            try {
                $this->eventObjects[$name] = new $event(...$this->filterServer(func_get_args()));
                $this->eventObjects[$name]->handle($this);
            } catch (\Exception $e) {
                $this->app->make(ExceptionHandler::class)->report($e);
            } catch (\Throwable $e) {
                $this->app->make(ExceptionHandler::class)->report(new FatalThrowableError($e));
            }
        });
    }