/**
  * @return string[]
  */
 public function getPageTypes()
 {
     $services = $this->manager->getAll();
     $types = array();
     foreach ($services as $id => $service) {
         $types[$id] = $service->getName();
     }
     asort($types);
     return $types;
 }
 /**
  * Handles a native error
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @throws mixed
  */
 private function handleNativeError(GetResponseForExceptionEvent $event)
 {
     if (true === $this->debug) {
         return;
     }
     if (true === $this->status) {
         return;
     }
     $this->status = true;
     $exception = $event->getException();
     $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
     $cmsManager = $this->cmsManagerSelector->retrieve();
     if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) {
         return;
     }
     if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) {
         return;
     }
     if (!$this->hasErrorCode($statusCode)) {
         return;
     }
     $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     $this->logException($exception, $exception, $message);
     try {
         $page = $this->getErrorCodePage($statusCode);
         $cmsManager->setCurrentPage($page);
         $response = $this->pageServiceManager->execute($page, $event->getRequest(), array(), new Response('', $statusCode));
     } catch (\Exception $e) {
         $this->logException($exception, $e);
         $event->setException($e);
         $this->handleInternalError($event);
         return;
     }
     $event->setResponse($response);
 }
 /**
  * Handles a native error.
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @throws mixed
  */
 private function handleNativeError(GetResponseForExceptionEvent $event)
 {
     if (true === $this->debug) {
         return;
     }
     if (true === $this->status) {
         return;
     }
     $this->status = true;
     $exception = $event->getException();
     $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
     $cmsManager = $this->cmsManagerSelector->retrieve();
     if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) {
         return;
     }
     if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) {
         return;
     }
     if (!$this->hasErrorCode($statusCode)) {
         return;
     }
     $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     $this->logException($exception, $exception, $message);
     try {
         $page = $this->getErrorCodePage($statusCode);
         $cmsManager->setCurrentPage($page);
         if ($page->getSite()->getLocale() !== $event->getRequest()->getLocale()) {
             // Compare locales because Request returns the default one if null.
             // If 404, LocaleListener from HttpKernel component of Symfony is not called.
             // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale.
             // So in order to translate messages, force here the locale with the site.
             $event->getRequest()->setLocale($page->getSite()->getLocale());
         }
         $response = $this->pageServiceManager->execute($page, $event->getRequest(), array(), new Response('', $statusCode));
     } catch (\Exception $e) {
         $this->logException($exception, $e);
         $event->setException($e);
         $this->handleInternalError($event);
         return;
     }
     $event->setResponse($response);
 }
 /**
  * Filter the `core.response` event to decorate the action.
  *
  * @param FilterResponseEvent $event
  *
  * @throws InternalErrorException
  */
 public function onCoreResponse(FilterResponseEvent $event)
 {
     $cms = $this->cmsSelector->retrieve();
     $response = $event->getResponse();
     $request = $event->getRequest();
     if ($this->cmsSelector->isEditor()) {
         $response->setPrivate();
         if (!$request->cookies->has('sonata_page_is_editor')) {
             $response->headers->setCookie(new Cookie('sonata_page_is_editor', 1));
         }
     }
     $page = $cms->getCurrentPage();
     // display a validation page before redirecting, so the editor can edit the current page
     if ($page && $response->isRedirection() && $this->cmsSelector->isEditor() && !$request->get('_sonata_page_skip')) {
         $response = new Response($this->templating->render('SonataPageBundle:Page:redirect.html.twig', array('response' => $response, 'page' => $page)));
         $response->setPrivate();
         $event->setResponse($response);
         return;
     }
     if (!$this->decoratorStrategy->isDecorable($event->getRequest(), $event->getRequestType(), $response)) {
         return;
     }
     if (!$this->cmsSelector->isEditor() && $request->cookies->has('sonata_page_is_editor')) {
         $response->headers->clearCookie('sonata_page_is_editor');
     }
     if (!$page) {
         throw new InternalErrorException('No page instance available for the url, run the sonata:page:update-core-routes and sonata:page:create-snapshots commands');
     }
     // only decorate hybrid page or page with decorate = true
     if (!$page->isHybrid() || !$page->getDecorate()) {
         return;
     }
     $parameters = array('content' => $response->getContent());
     $response = $this->pageServiceManager->execute($page, $request, $parameters, $response);
     if (!$this->cmsSelector->isEditor() && $page->isCms()) {
         $response->setTtl($page->getTtl());
     }
     $event->setResponse($response);
 }