|
@@ -27,42 +27,6 @@ class AutoloadGenerator
|
|
|
{
|
|
|
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
|
|
|
{
|
|
|
- $autoloadFile = <<<'EOF'
|
|
|
-<?php
|
|
|
-
|
|
|
-// autoload.php generated by Composer
|
|
|
-if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
|
|
- require __DIR__.'/ClassLoader.php';
|
|
|
-}
|
|
|
-
|
|
|
-$includePaths = require __DIR__.'/include_paths.php';
|
|
|
-
|
|
|
-if ($includePaths) {
|
|
|
- array_unshift($includePaths, get_include_path());
|
|
|
- set_include_path(join(PATH_SEPARATOR, $includePaths));
|
|
|
-}
|
|
|
-
|
|
|
-return call_user_func(function() {
|
|
|
- $loader = new \Composer\Autoload\ClassLoader();
|
|
|
-
|
|
|
- $map = require __DIR__.'/autoload_namespaces.php';
|
|
|
-
|
|
|
- foreach ($map as $namespace => $path) {
|
|
|
- $loader->add($namespace, $path);
|
|
|
- }
|
|
|
-
|
|
|
- $classMap = require __DIR__.'/autoload_classmap.php';
|
|
|
- if ($classMap) {
|
|
|
- $loader->addClassMap($classMap);
|
|
|
- }
|
|
|
-
|
|
|
- $loader->register();
|
|
|
-
|
|
|
- return $loader;
|
|
|
-});
|
|
|
-
|
|
|
-EOF;
|
|
|
-
|
|
|
$filesystem = new Filesystem();
|
|
|
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
|
|
|
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
|
|
@@ -138,10 +102,12 @@ EOF;
|
|
|
}
|
|
|
$classmapFile .= ");\n";
|
|
|
|
|
|
- file_put_contents($targetDir.'/autoload.php', $autoloadFile);
|
|
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
|
|
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
|
|
- file_put_contents($targetDir.'/include_paths.php', $this->getIncludePathsFile($packageMap));
|
|
|
+ if ($includePathFile = $this->getIncludePathsFile($packageMap)) {
|
|
|
+ file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
|
|
+ }
|
|
|
+ file_put_contents($targetDir.'/autoload.php', $this->getAutoloadFile(true, true, (Boolean) $includePathFile));
|
|
|
copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
|
|
|
}
|
|
|
|
|
@@ -230,8 +196,69 @@ EOF;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (!$includePaths) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
return sprintf(
|
|
|
"<?php\nreturn %s;\n", var_export($includePaths, true)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ protected function getAutoloadFile($usePSR0, $useClassMap, $useIncludePath)
|
|
|
+ {
|
|
|
+ $file = <<<'HEADER'
|
|
|
+<?php
|
|
|
+
|
|
|
+// autoload.php generated by Composer
|
|
|
+if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
|
|
+ require __DIR__.'/ClassLoader.php';
|
|
|
+}
|
|
|
+
|
|
|
+return call_user_func(function() {
|
|
|
+ $loader = new \Composer\Autoload\ClassLoader();
|
|
|
+
|
|
|
+
|
|
|
+HEADER;
|
|
|
+
|
|
|
+ if ($useIncludePath) {
|
|
|
+ $file .= <<<'INCLUDE_PATH'
|
|
|
+ $includePaths = require __DIR__.'/include_paths.php';
|
|
|
+ array_unshift($includePaths, get_include_path());
|
|
|
+ set_include_path(join(PATH_SEPARATOR, $includePaths));
|
|
|
+
|
|
|
+
|
|
|
+INCLUDE_PATH;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($usePSR0) {
|
|
|
+ $file .= <<<'PSR0'
|
|
|
+ $map = require __DIR__.'/autoload_namespaces.php';
|
|
|
+ foreach ($map as $namespace => $path) {
|
|
|
+ $loader->add($namespace, $path);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+PSR0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($useClassMap) {
|
|
|
+ $file .= <<<'CLASSMAP'
|
|
|
+ $classMap = require __DIR__.'/autoload_classmap.php';
|
|
|
+ if ($classMap) {
|
|
|
+ $loader->addClassMap($classMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+CLASSMAP;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $file . <<<'FOOTER'
|
|
|
+ $loader->register();
|
|
|
+
|
|
|
+ return $loader;
|
|
|
+});
|
|
|
+
|
|
|
+FOOTER;
|
|
|
+ }
|
|
|
}
|