bootstrap($configuration); $this->serviceManager = $application->getServiceManager(); $this->assertCompilerPreparation(); $this->initObjectManager(); } catch (\Exception $exception) { $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $output->writeln( '' . $exception->getMessage() . '' ); exit(static::RETURN_FAILURE); } if ($version == 'UNKNOWN') { $directoryList = new DirectoryList(BP); $composerJsonFinder = new ComposerJsonFinder($directoryList); $productMetadata = new ProductMetadata($composerJsonFinder); $version = $productMetadata->getVersion(); } parent::__construct($name, $version); } /** * {@inheritdoc} * * @throws \Exception The exception in case of unexpected error */ public function doRun(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $exitCode = parent::doRun($input, $output); if ($this->initException) { throw $this->initException; } return $exitCode; } /** * {@inheritdoc} */ protected function getDefaultCommands() { return array_merge(parent::getDefaultCommands(), $this->getApplicationCommands()); } /** * Gets application commands. * * @return array a list of available application commands */ protected function getApplicationCommands() { $commands = []; try { if (class_exists(\Magento\Setup\Console\CommandList::class)) { $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); $commands = array_merge($commands, $setupCommandList->getCommands()); } if ($this->objectManager->get(DeploymentConfig::class)->isAvailable()) { /** @var CommandListInterface */ $commandList = $this->objectManager->create(CommandListInterface::class); $commands = array_merge($commands, $commandList->getCommands()); } $commands = array_merge( $commands, $this->getVendorCommands($this->objectManager) ); } catch (\Exception $e) { $this->initException = $e; } return $commands; } /** * Object Manager initialization. * * @return void */ private function initObjectManager() { $params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $params = $this->documentRootResolver($params); $requestParams = $this->serviceManager->get('magento-init-params'); $appBootstrapKey = Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS; if (isset($requestParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) { $params[$appBootstrapKey] = $requestParams[$appBootstrapKey]; } $this->objectManager = Bootstrap::create(BP, $params)->getObjectManager(); /** @var ObjectManagerProvider $omProvider */ $omProvider = $this->serviceManager->get(ObjectManagerProvider::class); $omProvider->setObjectManager($this->objectManager); } /** * Checks whether compiler is being prepared. * * @return void * @throws GenerationDirectoryAccessException If generation directory is read-only */ private function assertCompilerPreparation() { /** * Temporary workaround until the compiler is able to clear the generation directory * @todo remove after MAGETWO-44493 resolved */ if (class_exists(CompilerPreparation::class)) { $compilerPreparation = new CompilerPreparation( $this->serviceManager, new Console\Input\ArgvInput(), new File() ); $compilerPreparation->handleCompilerEnvironment(); } } /** * Retrieves vendor commands. * * @param ObjectManagerInterface $objectManager the object manager * * @return array an array with external commands */ protected function getVendorCommands($objectManager) { $commands = []; foreach (CommandLocator::getCommands() as $commandListClass) { if (class_exists($commandListClass)) { $commands = array_merge( $commands, $objectManager->create($commandListClass)->getCommands() ); } } return $commands; } /** * Provides updated configuration in * accordance to document root settings. * * @param array $config * @return array */ private function documentRootResolver(array $config = []): array { $params = []; $deploymentConfig = $this->serviceManager->get(DeploymentConfig::class); if ((bool)$deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB)) { $params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [ DirectoryList::PUB => [DirectoryList::URL_PATH => ''], DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'], DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'], DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'], ]; } return array_merge_recursive($config, $params); } }