Generate a map separated from the autoloader, fixes #74
Also the loader is now returned by the autoload.phppull/77/merge
parent
b100df33d8
commit
1ca3e5e5e2
|
@ -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');
|
||||
|
||||
$file = file_get_contents(__DIR__.'/ClassLoader.php');
|
||||
$autoloadFile .= <<<'EOF'
|
||||
|
||||
$file .= <<<'EOF'
|
||||
|
||||
// autoload.php generated by composer
|
||||
// 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;
|
||||
}
|
||||
|
||||
return init();
|
||||
EOF;
|
||||
|
||||
$namespacesFile = <<<'EOF'
|
||||
<?php
|
||||
|
||||
// autoload_namespace.php generated by Composer
|
||||
|
||||
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();
|
||||
$namespacesFile .= ");\n";
|
||||
|
||||
EOF;
|
||||
|
||||
file_put_contents($targetFilename, $file);
|
||||
file_put_contents($targetDir.'/autoload.php', $autoloadFile);
|
||||
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
||||
}
|
||||
|
||||
private function parseAutoloads()
|
||||
|
|
|
@ -115,9 +115,9 @@ EOT
|
|||
|
||||
$localRepo->write();
|
||||
|
||||
$output->writeln('> Generating autoload.php');
|
||||
$output->writeln('> Generating autoload files');
|
||||
$generator = new AutoloadGenerator($localRepo, $composer->getPackage(), $installationManager);
|
||||
$generator->dump('vendor/.composer/autoload.php');
|
||||
$generator->dump('vendor/.composer/');
|
||||
|
||||
$output->writeln('> Done');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue