src/Service/Common/Formatter/Listener/ContainerInitListener.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Service\Common\Formatter\Listener;
  3. use App\Service\Common\Formatter\Container;
  4. use App\Service\Common\Formatter\Contract\IFormatter;
  5. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. class ContainerInitListener
  8. {
  9.     /**
  10.      * @var IFormatter
  11.      */
  12.     private IFormatter $formatter;
  13.     /**
  14.      * ContainerInitListener constructor.
  15.      *
  16.      * @param IFormatter $formatter
  17.      */
  18.     public function __construct(IFormatter $formatter)
  19.     {
  20.         $this->formatter $formatter;
  21.     }
  22.     /**
  23.      * On kernel request
  24.      *
  25.      * @param RequestEvent $event
  26.      */
  27.     public function onKernelRequest(RequestEvent $event): void
  28.     {
  29.         $this->init();
  30.     }
  31.     /**
  32.      * On command request
  33.      *
  34.      * @param ConsoleCommandEvent $event
  35.      */
  36.     public function onCommandRequest(ConsoleCommandEvent $event): void
  37.     {
  38.         $this->init();
  39.     }
  40.     /**
  41.      * Init container
  42.      *
  43.      * @return void
  44.      */
  45.     private function init(): void
  46.     {
  47.         Container::init($this->formatter);
  48.     }
  49. }