1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\AutoConfig;
13
14 use Composer\Script\Event;
15
16 class FakeAutoloadGenerator extends \Composer\Autoload\AutoloadGenerator
17 {
18 static public function sort_package_map(\Composer\Autoload\AutoloadGenerator $generator, $packageMap)
19 {
20 return $generator->sortPackageMap($packageMap);
21 }
22 }
23
24 class Generator
25 {
26 static public function on_autoload_dump(Event $event)
27 {
28 $composer = $event->getComposer();
29 $package = $composer->getPackage();
30 $generator = $composer->getAutoloadGenerator();
31 $packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
32 $packageMap = $generator->buildPackageMap($composer->getInstallationManager(), $package, $packages);
33 $sorted = FakeAutoloadGenerator::sort_package_map($generator, $packageMap);
34
35 $vendor_dir = $composer->getConfig()->get('vendor-dir');
36 $config = new Config(realpath($vendor_dir) . "/icanboogie/auto-config.php");
37
38 foreach ($sorted as $package_info)
39 {
40 list($package, $path) = $package_info;
41
42 $config->add_fragment($path, -10);
43 }
44
45 $config->add_fragment(getcwd(), 10);
46 $config->write();
47 }
48 }