serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') ->getServiceManager(); $generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager); if (!$generationDirectoryAccess->check()) { $output = new ConsoleOutput(); $output->writeln( 'Command line user does not have read and write permissions on var/generation directory. Please' . ' address this issue before using Magento command line.' ); exit(0); } /** * 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 ArgvInput(), new File()); $compilerPreparation->handleCompilerEnvironment(); } if ($version == 'UNKNOWN') { $directoryList = new DirectoryList(BP); $composerJsonFinder = new ComposerJsonFinder($directoryList); $productMetadata = new ProductMetadata($composerJsonFinder); $version = $productMetadata->getVersion(); } parent::__construct($name, $version); } /** * Process an error happened during initialization of commands, if any * * @param InputInterface $input * @param OutputInterface $output * @return int * @throws \Exception */ public function doRun(InputInterface $input, OutputInterface $output) { $exitCode = parent::doRun($input, $output); if ($this->initException) { $output->writeln( "We're sorry, an error occurred. Try clearing the cache and code generation directories. " . "By default, they are: var/cache, var/di, var/generation, and var/page_cache." ); throw $this->initException; } return $exitCode; } /** * {@inheritdoc} */ protected function getDefaultCommands() { return array_merge(parent::getDefaultCommands(), $this->getApplicationCommands()); } /** * Gets application commands * * @return array */ protected function getApplicationCommands() { $commands = []; try { $bootstrapParam = new ComplexParameter(self::INPUT_KEY_BOOTSTRAP); $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $bootstrap = Bootstrap::create(BP, $params); $objectManager = $bootstrap->getObjectManager(); /** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */ $omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider'); $omProvider->setObjectManager($objectManager); if (class_exists('Magento\Setup\Console\CommandList')) { $setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager); $commands = array_merge($commands, $setupCommandList->getCommands()); } if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { /** @var \Magento\Framework\Console\CommandListInterface */ $commandList = $objectManager->create(\Magento\Framework\Console\CommandListInterface::class); $commands = array_merge($commands, $commandList->getCommands()); } $commands = array_merge($commands, $this->getVendorCommands($objectManager)); } catch (\Exception $e) { $this->initException = $e; } return $commands; } /** * Gets vendor commands * * @param \Magento\Framework\ObjectManagerInterface $objectManager * @return array */ protected function getVendorCommands($objectManager) { $commands = []; foreach (CommandLocator::getCommands() as $commandListClass) { if (class_exists($commandListClass)) { $commands = array_merge( $commands, $objectManager->create($commandListClass)->getCommands() ); } } return $commands; } }