From 492b12d9bdecaeab1913a018ec727a87eaa2a18a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 1 Aug 2012 11:20:50 +0100
Subject: [PATCH] Issue #1663404 by effulgentsia, Rob Loach: Use Composer's
 defined namespaces to ease maintenance.

---
 core/includes/bootstrap.inc | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 171072c8c871..082db6ddb21f 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -3014,23 +3014,23 @@ function drupal_classloader() {
         break;
     }
 
-    // Register explicit PSR-0 vendor namespaces.
-    $loader->registerNamespaces(array(
-      // All Symfony-borrowed code lives in /core/vendor/symfony.
-      'Symfony\Component\ClassLoader' => DRUPAL_ROOT . '/core/vendor/symfony/class-loader',
-      'Symfony\Component\DependencyInjection' => DRUPAL_ROOT . '/core/vendor/symfony/dependency-injection',
-      'Symfony\Component\EventDispatcher' => DRUPAL_ROOT . '/core/vendor/symfony/event-dispatcher',
-      'Symfony\Component\HttpFoundation' => DRUPAL_ROOT . '/core/vendor/symfony/http-foundation',
-      'Symfony\Component\HttpKernel' => DRUPAL_ROOT . '/core/vendor/symfony/http-kernel',
-      'Symfony\Component\Routing' => DRUPAL_ROOT . '/core/vendor/symfony/routing',
-      'Symfony\Component\Yaml' => DRUPAL_ROOT . '/core/vendor/symfony/yaml',
-      'Doctrine\Common' => DRUPAL_ROOT . '/core/vendor/doctrine/common/lib',
-    ));
-    // Register PEAR-style vendor namespaces.
-    $loader->registerPrefixes(array(
-      // All Twig-borrowed code lives in /core/vendor/twig.
-      'Twig' => DRUPAL_ROOT . '/core/vendor/twig/twig/lib',
-    ));
+    // Register namespaces for vendor libraries managed by Composer.
+    $namespaces = require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php';
+    $prefixes = array();
+    foreach ($namespaces as $namespace => $path) {
+      // Composer combines libraries that use PHP 5.3 namespaces and ones that
+      // use PEAR-style class prefixes in a single array, but the Symfony class
+      // loader requires them to be registered separately. PSR-0 disallows
+      // underscores in namespace names and requires at least one in a
+      // PEAR-style class prefix.
+      if (strpos($namespace, '_') !== FALSE) {
+        $prefixes[$namespace] = $path;
+        unset($namespaces[$namespace]);
+      }
+    }
+    $loader->registerPrefixes($prefixes);
+    $loader->registerNamespaces($namespaces);
+
     // Register the Drupal namespace for classes in core as a fallback.
     // This allows to register additional namespaces within the Drupal namespace
     // (e.g., for modules) and avoids an additional file_exists() on the Drupal
-- 
GitLab