Browse Source

Make sure multiple autoload files can be used together, fixes #207

Jordi Boggiano 13 years ago
parent
commit
7222c111ed
1 changed files with 11 additions and 6 deletions
  1. 11 6
      src/Composer/Autoload/AutoloadGenerator.php

+ 11 - 6
src/Composer/Autoload/AutoloadGenerator.php

@@ -27,13 +27,16 @@ class AutoloadGenerator
 {
     public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
     {
-        $autoloadFile = file_get_contents(__DIR__.'/ClassLoader.php');
-        $autoloadFile .= <<<'EOF'
+        $autoloadFile = <<<'EOF'
+<?php
 
 // autoload.php generated by Composer
+if (!class_exists('Composer\\Autoload\\ClassLoader')) {
+    require __DIR__.'/ClassLoader.php';
+}
 
-function init() {
-    $loader = new ClassLoader();
+$__composer_autoload_init = function() {
+    $loader = new \Composer\Autoload\ClassLoader();
 
     $map = require __DIR__.'/autoload_namespaces.php';
 
@@ -44,9 +47,9 @@ function init() {
     $loader->register();
 
     return $loader;
-}
+};
 
-return init();
+return $__composer_autoload_init();
 EOF;
 
         $filesystem = new Filesystem();
@@ -117,6 +120,8 @@ EOF;
 
         file_put_contents($targetDir.'/autoload.php', $autoloadFile);
         file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
+        file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
+        copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
     }
 
     /**