src/EventSubscriber/WebsiteConfiguredSubscriber.php line 46

  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Bundle\FrameworkBundle\Console\Application;
  4. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\HttpKernel\KernelInterface;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. class WebsiteConfiguredSubscriber implements EventSubscriberInterface
  11. {
  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(), 'installer') === false && strpos($event->getRequest()->getPathInfo(), '_wdt') === false) {
  38.             $this->warmUpCaches();
  39.             $event->setResponse(new RedirectResponse($this->router->generate('installer_install')));
  40.         }
  41.     }
  42.     /**
  43.      * @inheritDoc
  44.      */
  45.     public static function getSubscribedEvents()
  46.     {
  47.         // TODO: Implement getSubscribedEvents() method.
  48.         return [
  49.             KernelEvents::REQUEST => 'onRequest',
  50.         ];
  51.     }
  52. }