src/EventSubscriber/WebsiteConfiguredSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. use Symfony\Bundle\FrameworkBundle\Console\Application;
  9. use Symfony\Component\HttpKernel\KernelInterface;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. class WebsiteConfiguredSubscriber implements EventSubscriberInterface {
  12.     private $params;
  13.     private $router;
  14.     private $kernelInterface;
  15.     public function __construct(ParameterBagInterface $paramsUrlGeneratorInterface $routerKernelInterface $kernelInterface) {
  16.         $this->params $params;
  17.         $this->router $router;
  18.         $this->kernelInterface $kernelInterface;
  19.     }
  20.     public function warmUpCaches() {
  21.         $application = new Application($this->kernelInterface);
  22.         $application->setAutoExit(false);
  23.         $wampupCacheProd = new \Symfony\Component\Console\Input\ArrayInput([
  24.             'command' => 'cache:warmup',
  25.             'env' => 'prod',
  26.         ]);
  27.         $outputWampupCacheProd = new \Symfony\Component\Console\Output\NullOutput();
  28.         $application->run($wampupCacheProd$outputWampupCacheProd);
  29.         $wampupCacheDev = new \Symfony\Component\Console\Input\ArrayInput([
  30.             'command' => 'cache:warmup',
  31.             'env' => 'dev',
  32.         ]);
  33.         $outputWampupCacheDev = new \Symfony\Component\Console\Output\NullOutput();
  34.         $application->run($wampupCacheDev$outputWampupCacheDev);
  35.     }
  36.     public function onRequest(RequestEvent $event) {
  37.         if ($this->params->get('is_website_configured') == '0' && strpos($event->getRequest()->getPathInfo(), 'install/install.php') === false && strpos($event->getRequest()->getPathInfo(), '_wdt') === false) {
  38.             $this->warmUpCaches();
  39.             $event->setResponse(new RedirectResponse($this->router->generate('installer_install')));
  40.         }
  41.     }
  42.     public static function getSubscribedEvents() {
  43.         return [
  44.             KernelEvents::REQUEST => 'onRequest',
  45.         ];
  46.     }
  47. }
  48. ?>