vendor/damienharper/auditor-bundle/src/Event/ConsoleEventSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DH\AuditorBundle\Event;
  4. use DH\Auditor\Configuration;
  5. use DH\Auditor\User\UserProviderInterface;
  6. use DH\AuditorBundle\User\ConsoleUserProvider;
  7. use Symfony\Component\Console\ConsoleEvents;
  8. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class ConsoleEventSubscriber implements EventSubscriberInterface
  11. {
  12.     private ConsoleUserProvider $consoleUserProvider;
  13.     private Configuration $configuration;
  14.     private UserProviderInterface $provider;
  15.     public function __construct(ConsoleUserProvider $consoleUserProviderConfiguration $configurationUserProviderInterface $provider)
  16.     {
  17.         $this->consoleUserProvider $consoleUserProvider;
  18.         $this->configuration $configuration;
  19.         $this->provider $provider;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ConsoleEvents::COMMAND => 'registerConsoleUserProvider',
  25.             ConsoleEvents::TERMINATE => 'restoreDefaultUserProvider',
  26.         ];
  27.     }
  28.     public function registerConsoleUserProvider(ConsoleCommandEvent $commandEvent): void
  29.     {
  30.         $command $commandEvent->getCommand();
  31.         $this->consoleUserProvider->setCurrentCommand($command);
  32.         $this->configuration->setUserProvider($this->consoleUserProvider);
  33.     }
  34.     public function restoreDefaultUserProvider(): void
  35.     {
  36.         $this->consoleUserProvider->setCurrentCommand(null);
  37.         $this->configuration->setUserProvider($this->provider);
  38.     }
  39. }