-
-
Save jfcherng/2fa6cccd68ad4cc84a31b974066db293 to your computer and use it in GitHub Desktop.
Revisions
-
jfcherng revised this gist
May 11, 2023 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,9 +35,8 @@ public function onMaintenance(RequestEvent $event): void { /** @var bool $isMaintenance */ $isMaintenance = \filter_var($_ENV['MAINTENANCE_MODE'] ?? '0', \FILTER_VALIDATE_BOOLEAN); if ($isMaintenance) { $event->setResponse(new Response( $this->twig->render('maintenance.html.twig'), Response::HTTP_SERVICE_UNAVAILABLE, -
jfcherng created this gist
Jun 9, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ MAINTENANCE_MODE=0 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ <?php declare(strict_types=1); namespace App\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Twig\Environment as TwigEnvironment; class KernelRequestSubscriber implements EventSubscriberInterface { private TwigEnvironment $twig; public function __construct(TwigEnvironment $twig) { $this->twig = $twig; } /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => [ ['onMaintenance', \PHP_INT_MAX - 1000], ], ]; } public function onMaintenance(RequestEvent $event): void { /** @var bool $isMaintenance */ $isMaintenance = \filter_var($_ENV['MAINTENANCE_MODE'] ?? '0', \FILTER_VALIDATE_BOOLEAN); $isCli = \PHP_SAPI === 'cli'; if ($isMaintenance && !$isCli) { $event->setResponse(new Response( $this->twig->render('maintenance.html.twig'), Response::HTTP_SERVICE_UNAVAILABLE, )); $event->stopPropagation(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Site temporarily under maintenance</title> </head> <body> <h1>Site temporarily under maintenance</h1> <p>Sorry for the inconvenience, we will get back soon!</p> </body> </html>