Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / src / Handler.php
index 71307322be9be7724761670a6d12ddcb14fa2e12..1bdefe0f69135a0aaa134a458c30a65c5fe87cde 100644 (file)
@@ -1,12 +1,10 @@
 <?php
 
-/**
- * @file
- * Contains \DrupalComposer\DrupalScaffold\Handler.
- */
-
 namespace DrupalComposer\DrupalScaffold;
 
+use Composer\Script\Event;
+use Composer\Installer\PackageEvent;
+use Composer\Plugin\CommandEvent;
 use Composer\Composer;
 use Composer\DependencyResolver\Operation\InstallOperation;
 use Composer\DependencyResolver\Operation\UpdateOperation;
@@ -18,6 +16,9 @@ use Composer\Util\Filesystem;
 use Composer\Util\RemoteFilesystem;
 use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
 
+/**
+ * Core class of the plugin, contains all logic which files should be fetched.
+ */
 class Handler {
 
   const PRE_DRUPAL_SCAFFOLD_CMD = 'pre-drupal-scaffold-cmd';
@@ -33,6 +34,13 @@ class Handler {
    */
   protected $io;
 
+  /**
+   * @var bool
+   *
+   * A boolean indicating if progress should be displayed.
+   */
+  protected $progress;
+
   /**
    * @var \Composer\Package\PackageInterface
    */
@@ -41,12 +49,34 @@ class Handler {
   /**
    * Handler constructor.
    *
-   * @param Composer $composer
-   * @param IOInterface $io
+   * @param \Composer\Composer $composer
+   * @param \Composer\IO\IOInterface $io
    */
   public function __construct(Composer $composer, IOInterface $io) {
     $this->composer = $composer;
     $this->io = $io;
+    $this->progress = TRUE;
+
+    // Pre-load all of our sources so that we do not run up
+    // against problems in `composer update` operations.
+    $this->manualLoad();
+  }
+
+  protected function manualLoad() {
+    $src_dir = __DIR__;
+
+    $classes = [
+      'CommandProvider',
+      'DrupalScaffoldCommand',
+      'FileFetcher',
+      'PrestissimoFileFetcher',
+    ];
+
+    foreach ($classes as $src) {
+      if (!class_exists('\\DrupalComposer\\DrupalScaffold\\' . $src)) {
+        include "{$src_dir}/{$src}.php";
+      }
+    }
   }
 
   /**
@@ -66,12 +96,26 @@ class Handler {
     return NULL;
   }
 
+  /**
+   * Get the command options.
+   *
+   * @param \Composer\Plugin\CommandEvent $event
+   */
+  public function onCmdBeginsEvent(CommandEvent $event) {
+    if ($event->getInput()->hasOption('no-progress')) {
+      $this->progress = !($event->getInput()->getOption('no-progress'));
+    }
+    else {
+      $this->progress = TRUE;
+    }
+  }
+
   /**
    * Marks scaffolding to be processed after an install or update command.
    *
    * @param \Composer\Installer\PackageEvent $event
    */
-  public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){
+  public function onPostPackageEvent(PackageEvent $event) {
     $package = $this->getCorePackage($event->getOperation());
     if ($package) {
       // By explicitly setting the core package, the onPostCmdEvent() will
@@ -85,7 +129,7 @@ class Handler {
    *
    * @param \Composer\Script\Event $event
    */
-  public function onPostCmdEvent(\Composer\Script\Event $event) {
+  public function onPostCmdEvent(Event $event) {
     // Only install the scaffolding if drupal/core was installed,
     // AND there are no scaffolding files present.
     if (isset($this->drupalCorePackage)) {
@@ -114,11 +158,12 @@ class Handler {
 
     $remoteFs = new RemoteFilesystem($this->io);
 
-    $fetcher = new PrestissimoFileFetcher($remoteFs, $options['source'], $files, $this->io, $this->composer->getConfig());
-    $fetcher->fetch($version, $webroot);
+    $fetcher = new PrestissimoFileFetcher($remoteFs, $options['source'], $this->io, $this->progress, $this->composer->getConfig());
+    $fetcher->setFilenames(array_combine($files, $files));
+    $fetcher->fetch($version, $webroot, TRUE);
 
-    $initialFileFetcher = new InitialFileFetcher($remoteFs, $options['source'], $this->getInitial());
-    $initialFileFetcher->fetch($version, $webroot);
+    $fetcher->setFilenames($this->getInitial());
+    $fetcher->fetch($version, $webroot, FALSE);
 
     // Call post-scaffold scripts.
     $dispatcher->dispatch(self::POST_DRUPAL_SCAFFOLD_CMD);
@@ -189,7 +234,7 @@ EOF;
    * Look up the Drupal core package object, or return it from where we cached
    * it in the $drupalCorePackage field.
    *
-   * @return PackageInterface
+   * @return \Composer\Package\PackageInterface
    */
   public function getDrupalCorePackage() {
     if (!isset($this->drupalCorePackage)) {
@@ -217,7 +262,7 @@ EOF;
   /**
    * Retrieve the path to the web root.
    *
-   *  @return string
+   * @return string
    */
   public function getWebRoot() {
     $drupalCorePackage = $this->getDrupalCorePackage();
@@ -235,7 +280,7 @@ EOF;
    * @param string $name
    *   Name of the package to get from the current composer installation.
    *
-   * @return PackageInterface
+   * @return \Composer\Package\PackageInterface
    */
   protected function getPackage($name) {
     return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
@@ -298,7 +343,7 @@ EOF;
       'excludes' => [],
       'includes' => [],
       'initial' => [],
-      'source' => 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
+      'source' => 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
       // Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path}
     ];
     return $options;
@@ -322,7 +367,7 @@ EOF;
     /**
      * Files from 8.3.x
      *
-     * @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
+     * @see https://cgit.drupalcode.org/drupal/tree/?h=8.3.x
      */
     $common = [
       '.csslintrc',
@@ -338,7 +383,7 @@ EOF;
       'sites/example.settings.local.php',
       'sites/example.sites.php',
       'update.php',
-      'web.config'
+      'web.config',
     ];
 
     // Version specific variations.