You are here

class CommandSubscriber in Update helper 8

Same name and namespace in other branches
  1. 2.x src/Events/CommandSubscriber.php \Drupal\update_helper\Events\CommandSubscriber

Subscriber for "generate:configuration:update" command.

Hierarchy

  • class \Drupal\update_helper\Events\CommandSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CommandSubscriber

1 string reference to 'CommandSubscriber'
console.services.yml in ./console.services.yml
console.services.yml
1 service uses CommandSubscriber
update_helper_checklist.command_subscriber in ./console.services.yml
Drupal\update_helper\Events\CommandSubscriber

File

src/Events/CommandSubscriber.php, line 11

Namespace

Drupal\update_helper\Events
View source
class CommandSubscriber implements EventSubscriberInterface {

  /**
   * Update hook generator for configuration update command.
   *
   * @var \Drupal\update_helper\Generator\ConfigurationUpdateHookGenerator
   */
  protected $generator;

  /**
   * Command subscriber class.
   *
   * @param \Drupal\update_helper\Generator\ConfigurationUpdateHookGenerator $generator
   *   Update hook generator service.
   */
  public function __construct(ConfigurationUpdateHookGenerator $generator) {
    $this->generator = $generator;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      UpdateHelperEvents::COMMAND_GCU_EXECUTE => [
        [
          'onExecute',
          10,
        ],
      ],
    ];
  }

  /**
   * Handles execute for configuration update generation to create update hook.
   *
   * @param \Drupal\update_helper\Events\CommandExecuteEvent $execute_event
   *   Command execute event.
   */
  public function onExecute(CommandExecuteEvent $execute_event) {

    // If command that triggered this event wasn't successful, then nothing
    // should be created.
    if (!$execute_event
      ->getSuccessful()) {
      return;
    }

    // Get options provided by command as options or in interactive mode.
    $options = $execute_event
      ->getOptions();

    // Generate update hook entry.
    $this->generator
      ->generate($execute_event
      ->getModule(), $execute_event
      ->getUpdateNumber(), $options['description']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandSubscriber::$generator protected property Update hook generator for configuration update command.
CommandSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CommandSubscriber::onExecute public function Handles execute for configuration update generation to create update hook.
CommandSubscriber::__construct public function Command subscriber class.