浏览代码

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

Jordi Boggiano 13 年之前
父节点
当前提交
7222c111ed
共有 1 个文件被更改,包括 11 次插入6 次删除
  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)
     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
 // 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';
     $map = require __DIR__.'/autoload_namespaces.php';
 
 
@@ -44,9 +47,9 @@ function init() {
     $loader->register();
     $loader->register();
 
 
     return $loader;
     return $loader;
-}
+};
 
 
-return init();
+return $__composer_autoload_init();
 EOF;
 EOF;
 
 
         $filesystem = new Filesystem();
         $filesystem = new Filesystem();
@@ -117,6 +120,8 @@ EOF;
 
 
         file_put_contents($targetDir.'/autoload.php', $autoloadFile);
         file_put_contents($targetDir.'/autoload.php', $autoloadFile);
         file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
         file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
+        file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
+        copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
     }
     }
 
 
     /**
     /**