Yaffs site version 1.1
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / src / Plugin.php
1 <?php
2 /**
3  * @file
4  * Contains DrupalComposer\DrupalScaffold\Plugin.
5  */
6
7 namespace DrupalComposer\DrupalScaffold;
8
9 use Composer\Composer;
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;
16
17 /**
18  * Composer plugin for handling drupal scaffold.
19  */
20 class Plugin implements PluginInterface, EventSubscriberInterface {
21
22   /**
23    * @var \DrupalComposer\DrupalScaffold\Handler
24    */
25   protected $handler;
26
27   /**
28    * {@inheritdoc}
29    */
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);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public static function getSubscribedEvents() {
42     return array(
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',
48     );
49   }
50
51   /**
52    * Post package event behaviour.
53    *
54    * @param \Composer\Installer\PackageEvent $event
55    */
56   public function postPackage(PackageEvent $event) {
57     $this->handler->onPostPackageEvent($event);
58   }
59
60   /**
61    * Post command event callback.
62    *
63    * @param \Composer\Script\Event $event
64    */
65   public function postCmd(\Composer\Script\Event $event) {
66     $this->handler->onPostCmdEvent($event);
67   }
68
69   /**
70    * Script callback for putting in composer scripts to download the
71    * scaffold files.
72    *
73    * @param \Composer\Script\Event $event
74    */
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();
80   }
81 }