|
@@ -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 = <<<EOF
|
|
|
|
|
|
- public static function autoload(\$class)
|
|
|
- {
|
|
|
- \$dir = $baseDirFromVendorDirCode . '/';
|
|
|
- \$prefixes = array($prefixes);
|
|
|
- foreach (\$prefixes as \$prefix) {
|
|
|
- if (0 !== strpos(\$class, \$prefix)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- \$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
|
|
- if (!\$path = stream_resolve_include_path(\$path)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- require \$path;
|
|
|
-
|
|
|
- return true;
|
|
|
+ public static function autoload(\$class)
|
|
|
+ {
|
|
|
+ \$dir = $baseDirFromTargetDirCode . '/';
|
|
|
+ \$prefixes = array($prefixes);
|
|
|
+ foreach (\$prefixes as \$prefix) {
|
|
|
+ if (0 !== strpos(\$class, \$prefix)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ \$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
|
|
+ if (!\$path = stream_resolve_include_path(\$path)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ require \$path;
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
EOF;
|
|
|
}
|
|
@@ -128,7 +128,7 @@ EOF;
|
|
|
$filesCode = "";
|
|
|
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
|
|
foreach ($autoloads['files'] as $functionFile) {
|
|
|
- $filesCode .= ' require '.$this->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 <<<AUTOLOAD
|
|
|
+<?php
|
|
|
+
|
|
|
+// autoload.php generated by Composer
|
|
|
+
|
|
|
+require_once $vendorPathToTargetDirCode . '/autoload_real$suffix.php';
|
|
|
+
|
|
|
+return ComposerAutoloaderInit$suffix::getLoader();
|
|
|
+
|
|
|
+AUTOLOAD;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix)
|
|
|
{
|
|
|
// TODO the class ComposerAutoloaderInit should be revert to a closure
|
|
|
// when APC has been fixed:
|
|
|
// - https://github.com/composer/composer/issues/959
|
|
|
// - https://bugs.php.net/bug.php?id=52144
|
|
|
// - https://bugs.php.net/bug.php?id=61576
|
|
|
+ // - https://bugs.php.net/bug.php?id=59298
|
|
|
|
|
|
if ($filesCode) {
|
|
|
$filesCode = "\n".$filesCode;
|
|
@@ -293,27 +311,27 @@ EOF;
|
|
|
$file = <<<HEADER
|
|
|
<?php
|
|
|
|
|
|
-// autoload.php generated by Composer
|
|
|
+// autoload_real$suffix.php generated by Composer
|
|
|
if (!class_exists('Composer\\\\Autoload\\\\ClassLoader', false)) {
|
|
|
- require $vendorPathToTargetDirCode . '/ClassLoader.php';
|
|
|
+ require __DIR__ . '/ClassLoader.php';
|
|
|
}
|
|
|
|
|
|
-if (!class_exists('ComposerAutoloaderInit$classSuffix', false)) {
|
|
|
- class ComposerAutoloaderInit$classSuffix
|
|
|
+class ComposerAutoloaderInit$suffix
|
|
|
+{
|
|
|
+ public static function getLoader()
|
|
|
{
|
|
|
- public static function getLoader()
|
|
|
- {
|
|
|
- \$loader = new \\Composer\\Autoload\\ClassLoader();
|
|
|
- \$composerDir = $vendorPathToTargetDirCode;
|
|
|
+ \$loader = new \\Composer\\Autoload\\ClassLoader();
|
|
|
+ \$vendorDir = $vendorPathCode;
|
|
|
+ \$baseDir = $appBaseDirCode;
|
|
|
|
|
|
|
|
|
HEADER;
|
|
|
|
|
|
if ($useIncludePath) {
|
|
|
$file .= <<<'INCLUDE_PATH'
|
|
|
- $includePaths = require $composerDir . '/include_paths.php';
|
|
|
- array_push($includePaths, get_include_path());
|
|
|
- set_include_path(join(PATH_SEPARATOR, $includePaths));
|
|
|
+ $includePaths = require __DIR__ . '/include_paths.php';
|
|
|
+ array_push($includePaths, get_include_path());
|
|
|
+ set_include_path(join(PATH_SEPARATOR, $includePaths));
|
|
|
|
|
|
|
|
|
INCLUDE_PATH;
|
|
@@ -321,10 +339,10 @@ INCLUDE_PATH;
|
|
|
|
|
|
if ($usePSR0) {
|
|
|
$file .= <<<'PSR0'
|
|
|
- $map = require $composerDir . '/autoload_namespaces.php';
|
|
|
- foreach ($map as $namespace => $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_AUTOLOAD
|
|
|
- spl_autoload_register(array('ComposerAutoloaderInit$classSuffix', 'autoload'));
|
|
|
+ spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'autoload'));
|
|
|
|
|
|
|
|
|
REGISTER_AUTOLOAD;
|
|
@@ -351,23 +369,21 @@ REGISTER_AUTOLOAD;
|
|
|
}
|
|
|
|
|
|
$file .= <<<METHOD_FOOTER
|
|
|
- \$loader->register();
|
|
|
+ \$loader->register();
|
|
|
$filesCode
|
|
|
- return \$loader;
|
|
|
- }
|
|
|
+ return \$loader;
|
|
|
+ }
|
|
|
|
|
|
METHOD_FOOTER;
|
|
|
|
|
|
$file .= $targetDirLoader;
|
|
|
|
|
|
return $file . <<<FOOTER
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-return ComposerAutoloaderInit$classSuffix::getLoader();
|
|
|
-
|
|
|
FOOTER;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|