commentParser = $commentParser; $this->configFilePool = $configFilePool; $this->configWriter = $configWriter; $this->scopeValidator = $scopeValidator; $this->collectorFactory = $collectorFactory; } /** * Processes the config:sensitive:set command. * * @param InputInterface $input The input manager * @param OutputInterface $output The output manager * @return void * @throws LocalizedException If scope or scope code is not valid * @throws RuntimeException If sensitive config can not be filled */ public function process(InputInterface $input, OutputInterface $output) { $scope = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_SCOPE); $scopeCode = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_SCOPE_CODE); $isInteractive = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_INTERACTIVE); $this->scopeValidator->isValid($scope, $scopeCode); $configPaths = $this->getConfigPaths(); $collector = $this->collectorFactory->create( $isInteractive ? CollectorFactory::TYPE_INTERACTIVE : CollectorFactory::TYPE_SIMPLE ); $values = $collector->getValues($input, $output, $configPaths); $this->configWriter->save($values, $scope, $scopeCode); $output->writeln(sprintf( 'Configuration value%s saved in app/etc/%s', $isInteractive ? 's' : '', $this->configFilePool->getPath(ConfigFilePool::APP_ENV) )); } /** * Get sensitive configuration paths. * * @return array * @throws LocalizedException if configuration file not exists or sensitive configuration is empty */ private function getConfigPaths() { $configFilePath = $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG); try { $configPaths = $this->commentParser->execute($configFilePath); } catch (FileSystemException $e) { throw new RuntimeException(__( 'File app/etc/%1 can\'t be read. Please check if it exists and has read permissions.', [ $configFilePath ] )); } if (empty($configPaths)) { throw new RuntimeException(__('There are no sensitive configurations to fill')); } return $configPaths; } }