|
@@ -35,39 +35,56 @@ class AutoloadGenerator
|
|
|
$this->installationManager = $installationManager;
|
|
|
}
|
|
|
|
|
|
- public function dump($targetFilename)
|
|
|
+ public function dump($targetDir)
|
|
|
{
|
|
|
- $autoloads = $this->parseAutoloads();
|
|
|
+ $autoloadFile = file_get_contents(__DIR__.'/ClassLoader.php');
|
|
|
+
|
|
|
+ $autoloadFile .= <<<'EOF'
|
|
|
+
|
|
|
+// autoload.php generated by Composer
|
|
|
+
|
|
|
+function init() {
|
|
|
+ $loader = new ClassLoader();
|
|
|
+
|
|
|
+ $map = require __DIR__.'/autoload_namespaces.php';
|
|
|
+
|
|
|
+ foreach ($map as $namespace => $path) {
|
|
|
+ $loader->add($namespace, $path);
|
|
|
+ }
|
|
|
+
|
|
|
+ $loader->register();
|
|
|
+
|
|
|
+ return $loader;
|
|
|
+}
|
|
|
|
|
|
- $file = file_get_contents(__DIR__.'/ClassLoader.php');
|
|
|
+return init();
|
|
|
+EOF;
|
|
|
|
|
|
- $file .= <<<'EOF'
|
|
|
+ $namespacesFile = <<<'EOF'
|
|
|
+<?php
|
|
|
|
|
|
-// autoload.php generated by composer
|
|
|
+// autoload_namespace.php generated by Composer
|
|
|
|
|
|
-$loader = new ClassLoader();
|
|
|
+return array(
|
|
|
|
|
|
EOF;
|
|
|
|
|
|
+ $autoloads = $this->parseAutoloads();
|
|
|
+
|
|
|
if (isset($autoloads['psr-0'])) {
|
|
|
foreach ($autoloads['psr-0'] as $def) {
|
|
|
foreach ($def['mapping'] as $prefix => $path) {
|
|
|
$exportedPrefix = var_export($prefix, true);
|
|
|
$exportedPath = var_export(($def['path'] ? '/'.$def['path'] : '').'/'.$path, true);
|
|
|
- $file .= <<<EOF
|
|
|
-\$loader->add($exportedPrefix, dirname(dirname(__DIR__)).$exportedPath);
|
|
|
-
|
|
|
-EOF;
|
|
|
+ $namespacesFile .= " $exportedPrefix => dirname(dirname(__DIR__)).$exportedPath,\n";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $file .= <<<'EOF'
|
|
|
-$loader->register();
|
|
|
-
|
|
|
-EOF;
|
|
|
+ $namespacesFile .= ");\n";
|
|
|
|
|
|
- file_put_contents($targetFilename, $file);
|
|
|
+ file_put_contents($targetDir.'/autoload.php', $autoloadFile);
|
|
|
+ file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
|
|
}
|
|
|
|
|
|
private function parseAutoloads()
|