Same name in this branch
  1. 10 composer/Plugin/Scaffold/Plugin.php \Drupal\Composer\Plugin\Scaffold\Plugin
  2. 10 core/lib/Drupal/Component/Annotation/Plugin.php \Drupal\Component\Annotation\Plugin
Same name and namespace in other branches
  1. 8.9.x composer/Plugin/Scaffold/Plugin.php \Drupal\Composer\Plugin\Scaffold\Plugin
  2. 9 composer/Plugin/Scaffold/Plugin.php \Drupal\Composer\Plugin\Scaffold\Plugin

Composer plugin for handling drupal scaffold.

@internal

Hierarchy

  • class \Drupal\Composer\Plugin\Scaffold\Plugin implements \Composer\Plugin\PluginInterface, \Composer\EventDispatcher\EventSubscriberInterface, \Composer\Plugin\Capable

Expanded class hierarchy of Plugin

8 string references to 'Plugin'
block.schema.yml in core/modules/block/config/schema/block.schema.yml
core/modules/block/config/schema/block.schema.yml
ContextualLinkManagerTest::testPluginDefinitionAlter in core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
Tests the plugins alter hook.
DefaultPluginManagerTest::testDefaultPluginManager in core/tests/Drupal/KernelTests/Core/Plugin/DefaultPluginManagerTest.php
Tests annotations and attributes on the default plugin manager.
FieldDefinitionIntegrityTest::testFieldPluginDefinitionIntegrity in core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php
Tests the integrity of field plugin definitions.
LayoutPluginManagerTest::setUpFilesystem in core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php
Sets up the filesystem with YAML files and annotated plugins.

... See full list

File

composer/Plugin/Scaffold/Plugin.php, line 24

Namespace

Drupal\Composer\Plugin\Scaffold
View source
class Plugin implements PluginInterface, EventSubscriberInterface, Capable {

  /**
   * The Composer service.
   *
   * @var \Composer\Composer
   */
  protected $composer;

  /**
   * Composer's I/O service.
   *
   * @var \Composer\IO\IOInterface
   */
  protected $io;

  /**
   * The Composer Scaffold handler.
   *
   * @var \Drupal\Composer\Plugin\Scaffold\Handler
   */
  protected $handler;

  /**
   * Record whether the 'require' command was called.
   *
   * @param bool
   */
  protected $requireWasCalled;

  /**
   * {@inheritdoc}
   */
  public function activate(Composer $composer, IOInterface $io) {
    $this->composer = $composer;
    $this->io = $io;
    $this->requireWasCalled = FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function deactivate(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
  public function uninstall(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
  public function getCapabilities() {
    return [
      CommandProvider::class => ScaffoldCommandProvider::class,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Important note: We only instantiate our handler on "post" events.
    return [
      ScriptEvents::POST_UPDATE_CMD => 'postCmd',
      ScriptEvents::POST_INSTALL_CMD => 'postCmd',
      PackageEvents::POST_PACKAGE_INSTALL => 'postPackage',
      PluginEvents::COMMAND => 'onCommand',
    ];
  }

  /**
   * Post command event callback.
   *
   * @param \Composer\Script\Event $event
   *   The Composer event.
   */
  public function postCmd(Event $event) {
    $this
      ->handler()
      ->scaffold();
  }

  /**
   * Post package event behavior.
   *
   * @param \Composer\Installer\PackageEvent $event
   *   Composer package event sent on install/update/remove.
   */
  public function postPackage(PackageEvent $event) {
    $this
      ->handler()
      ->onPostPackageEvent($event);
  }

  /**
   * Pre command event callback.
   *
   * @param \Composer\Plugin\CommandEvent $event
   *   The Composer command event.
   */
  public function onCommand(CommandEvent $event) {
    if ($event
      ->getCommandName() == 'require') {
      if ($this->handler) {
        throw new \Error('Core Scaffold Plugin handler instantiated too early. See https://www.drupal.org/project/drupal/issues/3104922');
      }
      $this->requireWasCalled = TRUE;
    }
  }

  /**
   * Instantiates the handler object upon demand.
   *
   * It is dangerous to update a Composer plugin if it loads any classes prior
   * to the `composer update` operation, and later tries to use them in a
   * post-update hook.
   */
  protected function handler() {
    if (!$this->handler) {
      $this->handler = new Handler($this->composer, $this->io);

      // On instantiation of our handler, notify it if the 'require' command
      // was executed.
      if ($this->requireWasCalled) {
        $this->handler
          ->requireWasCalled();
      }
    }
    return $this->handler;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Plugin::$composer protected property The Composer service.
Plugin::$handler protected property The Composer Scaffold handler.
Plugin::$io protected property Composer's I/O service.
Plugin::$requireWasCalled protected property Record whether the 'require' command was called.
Plugin::activate public function
Plugin::deactivate public function
Plugin::getCapabilities public function
Plugin::getSubscribedEvents public static function
Plugin::handler protected function Instantiates the handler object upon demand.
Plugin::onCommand public function Pre command event callback.
Plugin::postCmd public function Post command event callback.
Plugin::postPackage public function Post package event behavior.
Plugin::uninstall public function