Method that tries to save a route match into a cache

@param MvcEvent $event
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);
    }
1355965
public function init(MvcEvent $event): void
    {
        if (true === $this->tracyOptions->getEnabled()) {
            Debugger::enable($this->tracyOptions->getMode());

            if (null !== $this->tracyOptions->getEmail()) {
                Debugger::$email = $this->tracyOptions->getEmail();
            }

            if (null !== $this->tracyOptions->getLogDirectory()) {
                Debugger::$logDirectory = $this->tracyOptions->getLogDirectory();
            }

            if (null !== $this->tracyOptions->getLogSeverity()) {
                Debugger::$logSeverity = $this->tracyOptions->getLogSeverity();
            }

            if (null !== $this->tracyOptions->getMaxDepth()) {
                Debugger::$maxDepth = $this->tracyOptions->getMaxDepth();
            }

            if (null !== $this->tracyOptions->getMaxLength()) {
                Debugger::$maxLength = $this->tracyOptions->getMaxLength();
            }

            if (null !== $this->tracyOptions->getShowBar()) {
                Debugger::$showBar = $this->tracyOptions->getShowBar();
            }

            if (null !== $this->tracyOptions->getShowLocation()) {
                Debugger::$showLocation = $this->tracyOptions->getShowLocation();
            }

            if (null !== $this->tracyOptions->getStrict()) {
                Debugger::$strictMode = $this->tracyOptions->getStrict();
            }
        }
    }
741544
public function load(MvcEvent $mvcEvent)
    {
        $id = $this->getIdGenerator()->generate();
        if (!$this->getCacheStorage()->hasItem($id)) {
            return null;
        };

        $event = $this->createCacheEvent(CacheEvent::EVENT_LOAD, $mvcEvent, $id);

        $results = $this->getEventManager()->triggerEventUntil(function ($result) {
            return ($result === false);
        }, $event);

        if ($results->stopped()) {
            return null;
        }

        return $this->getCacheStorage()->getItem($id);
    }
717259
public function onRoute(MvcEvent $event)
    {
        $authService = $this->authService;

        $resource  = new PermResource();
        $match     = $event->getRouteMatch();
        $routeName = $match->getMatchedRouteName();
        $resource->setRouteName($routeName);

        if ($authService->isAllowed($resource, null))
            // Authorized User with Access
            return ;

        $authService->riseException(new AccessDeniedException());
    }
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;
    }
93272
public function checkDomain(MvcEvent $event)
    {
        if ($this->isConsoleRequest()) {
            return null;
        }

        $currentDomain = $this->siteService->getCurrentDomain();

        $site = $this->siteService->getCurrentSite($currentDomain);

        $redirectUrl = $this->domainRedirectService->getSiteNotAvailableRedirectUrl($site);

        if (!$site->isSiteAvailable() && empty($redirectUrl)) {
            $response = new Response();
            $response->setStatusCode(404);
            $event->stopPropagation(true);

            return $response;
        }

        if ($redirectUrl) {
            $response = new Response();
            $response->setStatusCode(302);
            $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);

            $event->stopPropagation(true);

            return $response;
        }

        $redirectUrl = $this->domainRedirectService->getPrimaryRedirectUrl($site);

        if ($redirectUrl) {
            $response = new Response();
            $response->setStatusCode(302);
            $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);

            $event->stopPropagation(true);

            return $response;
        }

        return null;
    }
528389
public function onPostRenderPage(RendererEvent $event)
    {
        // Checks if page caching is available
        $this->object = $event->getTarget();
        if (false === ($this->object instanceof Page) || false === $this->checkCachePageEvent()) {
            return;
        }

        // Checks if cache_id is available
        if (false === $cache_id = $this->getPageCacheId()) {
            return;
        }

        $column_uids = array();
        foreach ($this->object->getContentSet() as $column) {
            if ($column instanceof AbstractClassContent) {
                $column_uids[] = $column->getUid();
            }
        }

        $lifetime = $this->cache_page->getMinExpireByTag($column_uids);
        $render = $event->getRender();
        $this->cache_page->save($cache_id, $render, $lifetime, $this->object->getUid());
        $this->application->debug(sprintf(
            'Save cache (id: %s, lifetime: %d) for rendering `%s(%s)` with mode `%s`.',
            $cache_id,
            $lifetime,
            get_class($this->object),
            $this->object->getUid(),
            $event->getRenderer()->getMode()
        ));
    }
1200827
public function onRoute(MvcEvent $event)
    {
        $authService = $this->authService;

        $match = $event->getRouteMatch();
        if (!$authService->isAllowed(new PermResource(['route_match' => $match]), null))
            $authService->riseException();
    }
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;
    }
811790
public function onDispatchError( MvcEvent $event )
    {
        /* @var $exception \Exception  */
        $exception = $event->getParam( 'exception' );

        if ( $exception && $exception instanceof Exception )
        {
            $this->exceptionHandler( $exception, false );
        }

        if ( $this->response )
        {
            $event->stopPropagation();
            return $this->response;
        }
    }
236775
public function setSiteLayout(MvcEvent $event)
    {
        /** @var \Zend\View\Model\ViewModel $viewModel */
        $viewModel = $event->getViewModel();

        /* Add on for non CMS pages */
        $fakePage = new Page(
            Tracking::UNKNOWN_USER_ID,
            'Fake page for non CMS pages in ' . get_class($this)
        );
        $fakeRevision = new Revision(
            Tracking::UNKNOWN_USER_ID,
            'Fake revision for non CMS pages in ' . get_class($this)
        );

        $fakePage->setCurrentRevision($fakeRevision);

        $currentSite = $this->getCurrentSite();

        $viewModel->setVariable('page', $fakePage);
        $viewModel->setVariable('site', $currentSite);

        $template = $this->getSiteLayoutTemplate();

        $viewModel->setTemplate('layout/' . $template);

        return null;
    }
61980
public function preDispatch(MvcEvent $event)
    {
        $this->layout()->setVariable('lang', $this->params('lang'));

        $p       = $this->params()->fromQuery('p');
        $request = $this->getRequest();

        if ($p && $request->isXmlHttpRequest()) {
            $routeMatch = $event->getRouteMatch();
            $routeMatch->setParam('action', $p);
            $response = $this->getResponse();
            $response->getHeaders()
                     ->addHeaderLine('Content-Type', 'application/json')
                     ->addHeaderLine('Content-Encoding', 'utf8');
        }
    }
897156
public function onDispatch( MvcEvent $event )
    {
        $store   = $this->getStore();
        $request = $event->getRequest();
        $service = $this->getServiceLocator();
        $locale  = $service->get( 'AdminLocale' );
        $parent  = $request->getQuery( 'parentId' );

        if ( empty( $store['adminLocale'] ) )
        {
            $store['adminLocale'] = $locale->getCurrent();
        }

        if ( ! empty( $parent ) )
        {
            $store['parentId'] = $parent;
        }

        return parent::onDispatch( $event );
    }
604680
public function triggerEvent(string $event): void
    {
        // TODO: use event library and allow attach events to IFile and ICacheStateful.
        // cache triggers
        if ($this->file instanceof ICacheStateful) {
            switch ($event) {
                case self::EVENT_CACHED:
                    $this->file->setCachedAt($this->name, time());
                    break;
                case self::EVENT_EMPTY:
                case self::EVENT_ERROR:
                case self::EVENT_NOT_FOUND:
                    // TODO: split those and save different cases of cache state.
                    $this->file->setCachedAt($this->name, null);
                    break;
            }

            $this->file->saveState();
        }

        // other triggers
    }
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;
    	}
    	
    }
641089
public function onRoute(MvcEvent $e)
    {
        if (!$e->getRequest() instanceof HttpRequest || !$e->getResponse() instanceof HttpResponse) {
            return null;
        }

        /** @var HttpResponse $response */
        $response = $e->getResponse();

        $data = $this->getCacheService()->load($e);

        if ($data !== null) {
            $this->loadedFromCache = true;

            if ($this->getOptions()->getCacheResponse() === true) {
                $response = unserialize($data);
            } else {
                $response = $e->getResponse();
                $response->setContent($data);
            }

            $this->addDebugResponseHeader($response, 'Hit');

            return $response;
        }

        $this->addDebugResponseHeader($response, 'Miss');
    }
1156050
public function onRoute(MvcEvent $event)
    {
        /** @var \Zend\Http\Request $request */
        $request = $event->getRequest();
        if (!$this->isAllowed($request)) {
            $event->setError('error-unauthorized-route');
            /* @var $app \Zend\Mvc\Application */
            $app = $event->getTarget();
            $exception = new UnauthorizedAccessException('You are not currently allowed access to this page');
            $event->setParam('exception', $exception);
            $app->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);

            return false;
        }

        return true;
    }