function DevelCommands::interactEvent

Same name and namespace in other branches
  1. 4.x src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::interactEvent()

Asks the user to select an event and the event's implementation.

Attributes

#[CLI\Hook(type: HookManager::INTERACT, target: self::EVENT)]

File

src/Drush/Commands/DevelCommands.php, line 177

Class

DevelCommands

Namespace

Drupal\devel\Drush\Commands

Code

public function interactEvent(Input $input, Output $output) : void {
  $event = $input->getArgument('event');
  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 = $this->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 = $this->io()
      ->select('Enter the number of the implementation you wish to view.', $choices)) {
      throw new UserAbortException();
    }
    $input->setArgument('implementation', $choice);
  }
  else {
    throw new \Exception(dt('No implementations.'));
  }
}