objectManager = $objectManager; parent::__construct(); } /** * @inheritdoc */ protected function configure() { $description = 'Set application mode.'; $this->setName('deploy:mode:set') ->setDescription($description) ->setDefinition([ new InputArgument( self::MODE_ARGUMENT, InputArgument::REQUIRED, 'The application mode to set. Available options are "developer" or "production"' ), new InputOption( self::SKIP_COMPILATION_OPTION, 's', InputOption::VALUE_NONE, 'Skips the clearing and regeneration of static content (generated code, preprocessed CSS, ' . 'and assets in pub/static/)' ) ]); parent::configure(); } /** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { try { /** @var \Magento\Deploy\Model\Mode $modeController */ $modeController = $this->objectManager->create( \Magento\Deploy\Model\Mode::class, [ 'input' => $input, 'output' => $output, ] ); $toMode = $input->getArgument(self::MODE_ARGUMENT); $skipCompilation = $input->getOption(self::SKIP_COMPILATION_OPTION); switch ($toMode) { case State::MODE_DEVELOPER: $modeController->enableDeveloperMode(); break; case State::MODE_PRODUCTION: if ($skipCompilation) { $modeController->enableProductionModeMinimal(); } else { $modeController->enableProductionMode(); } break; case State::MODE_DEFAULT: $modeController->enableDefaultMode(); break; default: throw new LocalizedException(__('The mode can\'t be switched to "%1".', $toMode)); } $output->writeln('Enabled ' . $toMode . ' mode.'); return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } } }