From 2c065416eb0201a11e9233a9a19a50f831878c75 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 1 Aug 2012 10:12:46 +0200 Subject: [PATCH 1/3] [Autoload] generate an autoload_real.php file --- src/Composer/Autoload/AutoloadGenerator.php | 102 ++++++++++-------- .../Test/Autoload/AutoloadGeneratorTest.php | 2 + .../Autoload/Fixtures/autoload_functions.php | 31 +----- .../Fixtures/autoload_real_functions.php | 32 ++++++ .../Fixtures/autoload_real_target_dir.php | 49 +++++++++ .../Autoload/Fixtures/autoload_target_dir.php | 48 +-------- 6 files changed, 143 insertions(+), 121 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 69cd1fefe..b574e7f62 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')); @@ -94,23 +94,23 @@ EOF; $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($suffix)); + file_put_contents($vendorPath.'/autoload_real'.$suffix.'.php', $this->getAutoloadRealFile($vendorPathToTargetDirCode, true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $suffix)); copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); } @@ -278,7 +279,23 @@ EOF; return $baseDir.var_export($path, true); } - protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode, $classSuffix) + protected function getAutoloadFile($suffix) + { + + + return << $path) { - $loader->add($namespace, $path); - } + $map = require $composerDir . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->add($namespace, $path); + } PSR0; @@ -332,10 +348,10 @@ PSR0; if ($useClassMap) { $file .= <<<'CLASSMAP' - $classMap = require $composerDir . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } + $classMap = require $composerDir . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } CLASSMAP; @@ -343,7 +359,7 @@ CLASSMAP; if ($targetDirLoader) { $file .= <<register(); + \$loader->register(); $filesCode - return \$loader; - } + return \$loader; + } METHOD_FOOTER; $file .= $targetDirLoader; return $file . <<