Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SensitiveConfigSetFacade.php
Go to the documentation of this file.
1 <?php
7 
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
18 
23 {
29  private $commentParser;
30 
36  private $configFilePool;
37 
43  private $configWriter;
44 
50  private $scopeValidator;
51 
57  private $collectorFactory;
58 
66  public function __construct(
67  ConfigFilePool $configFilePool,
68  CommentParserInterface $commentParser,
69  ConfigWriter $configWriter,
70  ValidatorInterface $scopeValidator,
71  CollectorFactory $collectorFactory
72  ) {
73  $this->commentParser = $commentParser;
74  $this->configFilePool = $configFilePool;
75  $this->configWriter = $configWriter;
76  $this->scopeValidator = $scopeValidator;
77  $this->collectorFactory = $collectorFactory;
78  }
79 
89  public function process(InputInterface $input, OutputInterface $output)
90  {
91  $scope = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_SCOPE);
92  $scopeCode = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_SCOPE_CODE);
93  $isInteractive = $input->getOption(SensitiveConfigSetCommand::INPUT_OPTION_INTERACTIVE);
94 
95  $this->scopeValidator->isValid($scope, $scopeCode);
96  $configPaths = $this->getConfigPaths();
97  $collector = $this->collectorFactory->create(
99  );
100  $values = $collector->getValues($input, $output, $configPaths);
101 
102  $this->configWriter->save($values, $scope, $scopeCode);
103 
104  $output->writeln(sprintf(
105  '<info>Configuration value%s saved in app/etc/%s</info>',
106  $isInteractive ? 's' : '',
107  $this->configFilePool->getPath(ConfigFilePool::APP_ENV)
108  ));
109  }
110 
117  private function getConfigPaths()
118  {
119  $configFilePath = $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG);
120  try {
121  $configPaths = $this->commentParser->execute($configFilePath);
122  } catch (FileSystemException $e) {
123  throw new RuntimeException(__(
124  'File app/etc/%1 can\'t be read. Please check if it exists and has read permissions.',
125  [
126  $configFilePath
127  ]
128  ));
129  }
130 
131  if (empty($configPaths)) {
132  throw new RuntimeException(__('There are no sensitive configurations to fill'));
133  }
134 
135  return $configPaths;
136  }
137 }
__construct(ConfigFilePool $configFilePool, CommentParserInterface $commentParser, ConfigWriter $configWriter, ValidatorInterface $scopeValidator, CollectorFactory $collectorFactory)
$values
Definition: options.phtml:88
__()
Definition: __.php:13