Same filename in this branch
- 10 composer/Plugin/Scaffold/Plugin.php
- 10 core/lib/Drupal/Component/Annotation/Plugin.php
- 10 core/lib/Drupal/Component/Plugin/Attribute/Plugin.php
Same filename and directory in other branches
- 8.9.x composer/Plugin/Scaffold/Plugin.php
- 9 composer/Plugin/Scaffold/Plugin.php
Namespace
Drupal\Composer\Plugin\Scaffold
File
composer/Plugin/Scaffold/Plugin.php
View source
<?php
namespace Drupal\Composer\Plugin\Scaffold;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\Plugin\Capability\CommandProvider;
use Composer\Plugin\Capable;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Drupal\Composer\Plugin\Scaffold\CommandProvider as ScaffoldCommandProvider;
class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
protected $composer;
protected $io;
protected $handler;
protected $requireWasCalled;
public function activate(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
$this->requireWasCalled = FALSE;
}
public function deactivate(Composer $composer, IOInterface $io) {
}
public function uninstall(Composer $composer, IOInterface $io) {
}
public function getCapabilities() {
return [
CommandProvider::class => ScaffoldCommandProvider::class,
];
}
public static function getSubscribedEvents() {
return [
ScriptEvents::POST_UPDATE_CMD => 'postCmd',
ScriptEvents::POST_INSTALL_CMD => 'postCmd',
PackageEvents::POST_PACKAGE_INSTALL => 'postPackage',
PluginEvents::COMMAND => 'onCommand',
];
}
public function postCmd(Event $event) {
$this
->handler()
->scaffold();
}
public function postPackage(PackageEvent $event) {
$this
->handler()
->onPostPackageEvent($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;
}
}
protected function handler() {
if (!$this->handler) {
$this->handler = new Handler($this->composer, $this->io);
if ($this->requireWasCalled) {
$this->handler
->requireWasCalled();
}
}
return $this->handler;
}
}
Classes
Name |
Description |
Plugin |
Composer plugin for handling drupal scaffold. |