/** * Bootstrap method * @return $this|Application */ public function bootstrap() : self { if (!is_writable($this->info->vendorDir())) { throw new \RuntimeException('Vendor dir must be writable: ' . $this->info->vendorDir()); } if (!$this->info->installMode()) { $this->getBootstrapInstance()->bootstrap($this); $this->emit('system.init'); return $this; } $composer = $this->getComposerCLI()->getComposer(); $generator = $composer->getAutoloadGenerator(); $extra = $composer->getPackage()->getExtra(); $enabled = array(); $canonicalPacks = array(); /** @var CompletePackage[] $modules */ $modules = array(); $installer = null; if (!isset($extra['application']['installer'])) { throw new \RuntimeException('No installer defined'); } foreach ($composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages() as $package) { if ($package->getType() !== static::COMPOSER_TYPE) { $canonicalPacks[] = $package; continue; } $modules[$package->getName()] = $package; } if (!isset($modules[$extra['application']['installer']])) { throw new \RuntimeException("The specified installer was not found"); } $installer = $modules[$extra['application']['installer']]; $canonicalPacks[] = $installer; $enabled[] = $installer->getName(); foreach ($installer->getRequires() as $require) { $target = $require->getTarget(); if (isset($modules[$target])) { $canonicalPacks[] = $modules[$target]; $enabled[] = $modules[$target]->getName(); } } $packMap = $generator->buildPackageMap($composer->getInstallationManager(), $composer->getPackage(), $canonicalPacks); $autoload = $generator->parseAutoloads($packMap, $composer->getPackage()); $loader = $generator->createLoader($autoload); $this->classLoader->unregister(); $this->classLoader = $loader; $this->classLoader->register(); $this->getBootstrapInstance()->bootstrap($this); $this->getConfig()->write('modules.installed', $enabled); $this->getConfig()->write('modules.enabled', $enabled); $this->emit('system.init'); return $this; }