function DevelEventCommand::interact

File

src/Drush/Commands/DevelEventCommand.php, line 47

Class

DevelEventCommand
#[AsCommand(name: self::NAME, description: 'List implementations of a given event and optionally edit one.', aliases: [ 'fne', 'fn-event', 'event', ])]

Namespace

Drupal\devel\Drush\Commands

Code

protected function interact(InputInterface $input, OutputInterface $output) {
  $event = $input->getArgument('event');
  $io = new DrushStyle($input, $output);
  if (!$event) {
    // @todo Expand this list.
    $events = [
      'kernel.controller',
      'kernel.exception',
      'kernel.request',
      'kernel.response',
      'kernel.terminate',
      'kernel.view',
    ];
    $events = array_combine($events, $events);
    if (!$event = $io->select('Enter the event you wish to explore.', $events)) {
      throw new UserAbortException();
    }
    $input->setArgument('event', $event);
  }
  /** @var \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher */
  $event_dispatcher = $this->eventDispatcher;
  if ($implementations = $event_dispatcher->getListeners($event)) {
    $choices = [];
    foreach ($implementations as $implementation) {
      $callable = $implementation[0]::class . '::' . $implementation[1];
      $choices[$callable] = $callable;
    }
    if (!$choice = $io->select('Select the implementation you wish to view.', $choices)) {
      throw new UserAbortException();
    }
    $input->setArgument('implementation', $choice);
  }
  else {
    throw new \Exception(dt('No implementations.'));
  }
}