4 * Contains DrupalComposer\DrupalScaffold\Plugin.
7 namespace DrupalComposer\DrupalScaffold;
10 use Composer\EventDispatcher\EventSubscriberInterface;
11 use Composer\Installer\PackageEvent;
12 use Composer\Installer\PackageEvents;
13 use Composer\IO\IOInterface;
14 use Composer\Plugin\PluginInterface;
15 use Composer\Script\ScriptEvents;
18 * Composer plugin for handling drupal scaffold.
20 class Plugin implements PluginInterface, EventSubscriberInterface {
23 * @var \DrupalComposer\DrupalScaffold\Handler
30 public function activate(Composer $composer, IOInterface $io) {
31 // We use a separate PluginScripts object. This way we separate
32 // functionality and also avoid some debug issues with the plugin being
33 // copied on initialisation.
34 // @see \Composer\Plugin\PluginManager::registerPackage()
35 $this->handler = new Handler($composer, $io);
41 public static function getSubscribedEvents() {
43 PackageEvents::POST_PACKAGE_INSTALL => 'postPackage',
44 PackageEvents::POST_PACKAGE_UPDATE => 'postPackage',
45 //PackageEvents::POST_PACKAGE_UNINSTALL => 'postPackage',
46 //ScriptEvents::POST_INSTALL_CMD => 'postCmd',
47 ScriptEvents::POST_UPDATE_CMD => 'postCmd',
52 * Post package event behaviour.
54 * @param \Composer\Installer\PackageEvent $event
56 public function postPackage(PackageEvent $event) {
57 $this->handler->onPostPackageEvent($event);
61 * Post command event callback.
63 * @param \Composer\Script\Event $event
65 public function postCmd(\Composer\Script\Event $event) {
66 $this->handler->onPostCmdEvent($event);
70 * Script callback for putting in composer scripts to download the
73 * @param \Composer\Script\Event $event
75 public static function scaffold(\Composer\Script\Event $event) {
76 $handler = new Handler($event->getComposer(), $event->getIO());
77 $handler->downloadScaffold();
78 // Generate the autoload.php file after generating the scaffold files.
79 $handler->generateAutoload();