/** * Check if the user is logged in when requesting an account route, if not * redirect to the homepage. * * @param Event $event */ public function checkLoggedIn(KernelEvent $event) { $user = $this->get('user.current'); if ($user instanceof AnonymousUser and is_array($event->getRequest()->get('_route_collections')) and in_array('ms.user.account', $event->getRequest()->get('_route_collections'))) { $event->setResponse(new RedirectResponse('/')); } }
/** * Method called on kernel.request event. Handle only "subrequest" * @param KernelEvent $event The received event * * @return void */ public function onKernelRequest(KernelEvent $event) { if (HttpKernelInterface::MASTER_REQUEST == $event->getRequestType() || null === $this->cacheService) { return; } $request = $event->getRequest(); if ($request->attributes->has('server_cache')) { $cacheKey = $this->getRequestCacheKey($request); $request->attributes->set('cache_key', $cacheKey); $controller = $request->attributes->get('controllerName'); $fromCache = false; $responseContent = $this->cacheService->get($cacheKey); if ($responseContent || $responseContent === '' && !$request->attributes->get('ignore_errors')) { $response = new Response($responseContent); $response->headers->set('server_cached', 1); $event->setResponse($response); if ($this->debug) { $this->decorateResponse($request, $response, $controller, true); } $fromCache = true; } $this->cachedBlocks[$controller . ' - key : ' . $cacheKey] = $fromCache; } }