src/Controller/Website/ErrorController.php line 36

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Psr\Container\ContainerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as Controller;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\ErrorHandler\Exception\FlattenException;
  11. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  12. /**
  13.  * @Route(
  14.  *      schemes         = {"http|https"}
  15.  * )
  16.  * @Cache(
  17.  *      maxage          = "0",
  18.  *      smaxage         = "0",
  19.  *      expires         = "now",
  20.  *      public          = false
  21.  * )
  22.  */
  23. class ErrorController extends Controller {
  24.     /**
  25.      * @Route(
  26.      *      path          = "/error",
  27.      *      name          = "error",
  28.      *      methods       = {"GET"}
  29.      * )
  30.      */
  31.     public function errorPage(Request $requestFlattenException $exception
  32.                               ContainerInterface $container) {
  33.         
  34.         $debug = (int)$request->get('debug');
  35.         $eadToken $container->getParameter('ead-token');
  36.         $errorMessage $exception->getMessage();
  37.         $data = [
  38.             "debug" => $debug,
  39.             "errorMessage" => $errorMessage,
  40.         ];
  41.         if(
  42.             $request->isXmlHttpRequest() ||
  43.             $request->getClientIp() == "191.209.18.215" ||
  44.             $eadToken['sandbox'
  45.         ){
  46.             return new JsonResponse(
  47.                 json_encode($data), 
  48.                 Response::HTTP_INTERNAL_SERVER_ERROR
  49.                 [], 
  50.                 true
  51.             );
  52.         }
  53.         $response = new Response();
  54.         $content "<html>
  55.             <head>
  56.                 <title>error</title>
  57.                 <style>
  58.                     @import url('https://fonts.googleapis.com/css2?family=Lato:wght@300&display=swap');
  59.                     body{
  60.                         background: linear-gradient(to right, #efefef, #fff);
  61.                     }
  62.                     .content{
  63.                         position: absolute;
  64.                         width: 300px;
  65.                         z-index: 15;
  66.                         top: 50%;
  67.                         left: 50%;
  68.                         margin: -15em 0 0 -150px;
  69.                         text-align: center;
  70.                         font-family: 'Lato';
  71.                     }
  72.                     .space{
  73.                         margin-top: 1em;
  74.                     }
  75.                     .box-logo{
  76.                         max-width: 240px;
  77.                     }
  78.                     .back{
  79.                         text-decoration: none;
  80.                         color: #333;
  81.                         font-weight: 800;
  82.                     }
  83.                     .back:hover{
  84.                         text-decoration: underline;
  85.                     }
  86.                 </style>
  87.             </head>
  88.             <body>
  89.                 ".
  90.                 (
  91.                     $debug 
  92.                     "<div style='border-color: black;
  93.                             border: inset;
  94.                             color: white;
  95.                             background: #c44242;'>
  96.                         <pre>{$errorMessage}</pre>
  97.                     </div>" 
  98.                     ''
  99.                 )
  100.                 ."<div class='content'>
  101.                     <img 
  102.                         alt='logo'
  103.                         class='box-logo'
  104.                         src='https://i.imgur.com/k99dhkb.png'
  105.                     />
  106.                     <div class='space'></div>
  107.                     <h1>Ops...</h1>
  108.                     <h3>Esse link está em manutenção. <br/> Tente acessar em alguns minutos.</h3>
  109.                     <div class='space'></div>
  110.                     <span><br/>
  111.                         <a class='back' href='/'>
  112.                             Voltar ao início
  113.                         </a>
  114.                     </span>
  115.                 </div>
  116.             </body>
  117.         </html>";
  118.         $response->setContent($content);
  119.         $response->headers->set('Content-Type''text/html');
  120.         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
  121.         return $response;
  122.     }
  123. }