diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 69cd1fefe..e49b16bc3 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -25,7 +25,7 @@ use Composer\Util\Filesystem; */ class AutoloadGenerator { - public function dump(Config $config, RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $classSuffix = '') + public function dump(Config $config, RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $suffix = '') { $filesystem = new Filesystem(); $filesystem->ensureDirectoryExists($config->get('vendor-dir')); @@ -90,27 +90,27 @@ EOF; $prefixes = implode(', ', array_map(function ($prefix) { return var_export($prefix, true); }, array_keys($mainAutoload['psr-0']))); - $baseDirFromVendorDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true); + $baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, getcwd(), true); $targetDirLoader = <<getPathCode($filesystem, $relVendorPath, $vendorPath, $functionFile).";\n"; + $filesCode .= ' require '.$this->getPathCode($filesystem, $relVendorPath, $vendorPath, $functionFile).";\n"; } file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile); @@ -136,7 +136,8 @@ EOF; if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)) { file_put_contents($targetDir.'/include_paths.php', $includePathFile); } - file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $classSuffix)); + file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); + file_put_contents($targetDir.'/autoload_real'.$suffix.'.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix)); copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); } @@ -278,13 +279,30 @@ EOF; return $baseDir.var_export($path, true); } - protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode, $classSuffix) + protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix) + { + + + return << $path) { - $loader->add($namespace, $path); - } + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->add($namespace, $path); + } PSR0; @@ -332,10 +350,10 @@ PSR0; if ($useClassMap) { $file .= <<<'CLASSMAP' - $classMap = require $composerDir . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } CLASSMAP; @@ -343,7 +361,7 @@ CLASSMAP; if ($targetDirLoader) { $file .= <<register(); + \$loader->register(); $filesCode - return \$loader; - } + return \$loader; + } METHOD_FOOTER; $file .= $targetDirLoader; return $file . <<