Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Plugin.php

class Plugin

Same name in this branch
  1. 11.1.x vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php \PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin
  2. 11.1.x vendor/phpstan/extension-installer/src/Plugin.php \PHPStan\ExtensionInstaller\Plugin
  3. 11.1.x vendor/php-http/discovery/src/Composer/Plugin.php \Http\Discovery\Composer\Plugin
  4. 11.1.x vendor/composer/installers/src/Composer/Installers/Plugin.php \Composer\Installers\Plugin
  5. 11.1.x vendor/tbachert/spi/src/Composer/Plugin.php \Nevay\SPI\Composer\Plugin
  6. 11.1.x core/lib/Drupal/Component/Annotation/Plugin.php \Drupal\Component\Annotation\Plugin
  7. 11.1.x core/lib/Drupal/Component/Plugin/Attribute/Plugin.php \Drupal\Component\Plugin\Attribute\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

14 string references to 'Plugin'
Action::create in core/modules/system/src/Entity/Action.php
Constructs a new entity object, without permanently saving it.
block.schema.yml in core/modules/block/config/schema/block.schema.yml
core/modules/block/config/schema/block.schema.yml
DisplayPluginBase::calculateCacheMetadata in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Calculates the display's cache metadata by inspecting each handler/plugin.
DisplayPluginBase::getAllPlugins in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Gets all the plugins used by the display.
EntityBlock::getEntityId in core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
Gets the entity ID of the row.

... 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.
     *
     * @var 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

Title Sort descending Modifiers Object type Summary Overriden Title
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 Apply plugin modifications to Composer Overrides PluginInterface::activate
Plugin::deactivate public function Remove any hooks from Composer Overrides PluginInterface::deactivate
Plugin::getCapabilities public function Method by which a Plugin announces its API implementations, through an array
with a special structure.
Overrides Capable::getCapabilities
Plugin::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents
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 Prepare the plugin to be uninstalled Overrides PluginInterface::uninstall
PluginInterface::PLUGIN_API_VERSION public constant Version number of the internal composer-plugin-api package

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal