Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Composer / Composer.php
index bdb0127c467c39029d6fe8b94bb30c518b19cb3e..016f93a348563fedff4cf50db03e7b87b8245b1d 100644 (file)
@@ -72,35 +72,42 @@ class Composer {
    * Add vendor classes to Composer's static classmap.
    */
   public static function preAutoloadDump(Event $event) {
+    // Get the configured vendor directory.
+    $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');
+
     // We need the root package so we can add our classmaps to its loader.
     $package = $event->getComposer()->getPackage();
     // We need the local repository so that we can query and see if it's likely
     // that our files are present there.
     $repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
     // This is, essentially, a null constraint. We only care whether the package
-    // is present in vendor/ yet, but findPackage() requires it.
+    // is present in the vendor directory yet, but findPackage() requires it.
     $constraint = new Constraint('>', '');
+    // It's possible that there is no classmap specified in a custom project
+    // composer.json file. We need one so we can optimize lookup for some of our
+    // dependencies.
+    $autoload = $package->getAutoload();
+    if (!isset($autoload['classmap'])) {
+      $autoload['classmap'] = [];
+    }
     // Check for our packages, and then optimize them if they're present.
     if ($repository->findPackage('symfony/http-foundation', $constraint)) {
-      $autoload = $package->getAutoload();
       $autoload['classmap'] = array_merge($autoload['classmap'], [
-        'vendor/symfony/http-foundation/Request.php',
-        'vendor/symfony/http-foundation/ParameterBag.php',
-        'vendor/symfony/http-foundation/FileBag.php',
-        'vendor/symfony/http-foundation/ServerBag.php',
-        'vendor/symfony/http-foundation/HeaderBag.php',
+        $vendor_dir . '/symfony/http-foundation/Request.php',
+        $vendor_dir . '/symfony/http-foundation/ParameterBag.php',
+        $vendor_dir . '/symfony/http-foundation/FileBag.php',
+        $vendor_dir . '/symfony/http-foundation/ServerBag.php',
+        $vendor_dir . '/symfony/http-foundation/HeaderBag.php',
       ]);
-      $package->setAutoload($autoload);
     }
     if ($repository->findPackage('symfony/http-kernel', $constraint)) {
-      $autoload = $package->getAutoload();
       $autoload['classmap'] = array_merge($autoload['classmap'], [
-        'vendor/symfony/http-kernel/HttpKernel.php',
-        'vendor/symfony/http-kernel/HttpKernelInterface.php',
-        'vendor/symfony/http-kernel/TerminableInterface.php',
+        $vendor_dir . '/symfony/http-kernel/HttpKernel.php',
+        $vendor_dir . '/symfony/http-kernel/HttpKernelInterface.php',
+        $vendor_dir . '/symfony/http-kernel/TerminableInterface.php',
       ]);
-      $package->setAutoload($autoload);
     }
+    $package->setAutoload($autoload);
   }
 
   /**