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 b6ca659cd0794912c5ed181d325487aebaae94d4..1bdefe0f69135a0aaa134a458c30a65c5fe87cde 100644 (file)
@@ -1,22 +1,24 @@
 <?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;
 use Composer\EventDispatcher\EventDispatcher;
 use Composer\IO\IOInterface;
 use Composer\Package\PackageInterface;
+use Composer\Semver\Semver;
 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';
@@ -32,6 +34,13 @@ class Handler {
    */
   protected $io;
 
+  /**
+   * @var bool
+   *
+   * A boolean indicating if progress should be displayed.
+   */
+  protected $progress;
+
   /**
    * @var \Composer\Package\PackageInterface
    */
@@ -40,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";
+      }
+    }
   }
 
   /**
@@ -65,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
@@ -84,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)) {
@@ -113,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);
@@ -188,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)) {
@@ -216,7 +262,7 @@ EOF;
   /**
    * Retrieve the path to the web root.
    *
-   *  @return string
+   * @return string
    */
   public function getWebRoot() {
     $drupalCorePackage = $this->getDrupalCorePackage();
@@ -234,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, '*');
@@ -297,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;
@@ -321,13 +367,12 @@ 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',
       '.editorconfig',
       '.eslintignore',
-      '.eslintrc.json',
       '.gitattributes',
       '.htaccess',
       'index.php',
@@ -338,17 +383,18 @@ EOF;
       'sites/example.settings.local.php',
       'sites/example.sites.php',
       'update.php',
-      'web.config'
+      'web.config',
     ];
 
     // Version specific variations.
-    switch ($version) {
-      case '8.0':
-      case '8.1':
-      case '8.2':
-        $common[] = '.eslintrc';
-        $common = array_diff($common, ['.eslintrc.json']);
-        break;
+    if (Semver::satisfies($version, '<8.3')) {
+      $common[] = '.eslintrc';
+    }
+    if (Semver::satisfies($version, '>=8.3')) {
+      $common[] = '.eslintrc.json';
+    }
+    if (Semver::satisfies($version, '>=8.5')) {
+      $common[] = '.ht.router.php';
     }
 
     sort($common);