|
@@ -108,6 +108,104 @@ EOT
|
|
}
|
|
}
|
|
|
|
|
|
$localRepo->write();
|
|
$localRepo->write();
|
|
|
|
+
|
|
|
|
+ $output->writeln('> Generating autoload.php');
|
|
|
|
+ $this->generateAutoload($composer, $installationManager);
|
|
|
|
+
|
|
$output->writeln('> Done');
|
|
$output->writeln('> Done');
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private function generateAutoload(\Composer\Composer $composer,
|
|
|
|
+ \Composer\Installer\InstallationManager $installationManager)
|
|
|
|
+ {
|
|
|
|
+ $localRepo = new \Composer\Repository\FilesystemRepository(
|
|
|
|
+ new \Composer\Json\JsonFile('.composer/installed.json'));
|
|
|
|
+
|
|
|
|
+ $installPaths = array();
|
|
|
|
+ foreach ($localRepo->getPackages() as $package) {
|
|
|
|
+ $installPaths[] = array(
|
|
|
|
+ $this->getFullPackage($package, $installationManager),
|
|
|
|
+ $installationManager->getInstallPath($package)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ $installPaths[] = array($composer->getPackage(), '');
|
|
|
|
+
|
|
|
|
+ $autoloads = array();
|
|
|
|
+ foreach ($installPaths as $item) {
|
|
|
|
+ list($package, $installPath) = $item;
|
|
|
|
+
|
|
|
|
+ if (null !== $package->getInstallAs()) {
|
|
|
|
+ $installPath = substr($installPath, 0, -strlen('/'.$package->getInstallAs()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($package->getAutoload() as $type => $mapping) {
|
|
|
|
+ $autoloads[$type] = isset($autoloads[$type]) ? $autoloads[$type] : array();
|
|
|
|
+ $autoloads[$type][] = array(
|
|
|
|
+ 'mapping' => $mapping,
|
|
|
|
+ 'path' => $installPath,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->dumpAutoload($autoloads);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function dumpAutoload(array $autoloads)
|
|
|
|
+ {
|
|
|
|
+ $file = <<<'EOF'
|
|
|
|
+<?php
|
|
|
|
+// autoload.php generated by composer
|
|
|
|
+
|
|
|
|
+require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
|
|
|
+
|
|
|
|
+use Symfony\Component\ClassLoader\UniversalClassLoader;
|
|
|
|
+
|
|
|
|
+$loader = new UniversalClassLoader();
|
|
|
|
+
|
|
|
|
+EOF;
|
|
|
|
+
|
|
|
|
+ if (isset($autoloads['psr0'])) {
|
|
|
|
+ foreach ($autoloads['psr0'] as $def) {
|
|
|
|
+ foreach ($def['mapping'] as $namespace => $path) {
|
|
|
|
+ $exportedNamespace = var_export($namespace, true);
|
|
|
|
+ $exportedPath = var_export(($def['path'] ? '/'.$def['path'] : '').'/'.$path, true);
|
|
|
|
+ $file .= <<<EOF
|
|
|
|
+\$loader->registerNamespace($exportedNamespace, dirname(__DIR__).$exportedPath);
|
|
|
|
+
|
|
|
|
+EOF;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isset($autoloads['pear'])) {
|
|
|
|
+ foreach ($autoloads['pear'] 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->registerPrefix($exportedPrefix, dirname(__DIR__).$exportedPath);
|
|
|
|
+
|
|
|
|
+EOF;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $file .= <<<'EOF'
|
|
|
|
+$loader->register();
|
|
|
|
+
|
|
|
|
+EOF;
|
|
|
|
+
|
|
|
|
+ file_put_contents('.composer/autoload.php', $file);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function getFullPackage(\Composer\Package\PackageInterface $package,
|
|
|
|
+ \Composer\Installer\InstallationManager $installationManager)
|
|
|
|
+ {
|
|
|
|
+ $path = $installationManager->getInstallPath($package);
|
|
|
|
+
|
|
|
|
+ $loader = new \Composer\Package\Loader\JsonLoader();
|
|
|
|
+ $fullPackage = $loader->load(new \Composer\Json\JsonFile($path.'/composer.json'));
|
|
|
|
+
|
|
|
|
+ return $fullPackage;
|
|
|
|
+ }
|
|
}
|
|
}
|