Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessorFacade.php
Go to the documentation of this file.
1 <?php
7 
20 
30 {
39  private $scopeValidator;
40 
48  private $pathValidator;
49 
55  private $configSetProcessorFactory;
56 
62  private $hash;
63 
69  private $scopeConfig;
70 
78  public function __construct(
79  ValidatorInterface $scopeValidator,
80  PathValidator $pathValidator,
81  ConfigSetProcessorFactory $configSetProcessorFactory,
82  Hash $hash,
83  ScopeConfigInterface $scopeConfig
84  ) {
85  $this->scopeValidator = $scopeValidator;
86  $this->pathValidator = $pathValidator;
87  $this->configSetProcessorFactory = $configSetProcessorFactory;
88  $this->hash = $hash;
89  $this->scopeConfig = $scopeConfig;
90  }
91 
106  public function process($path, $value, $scope, $scopeCode, $lock)
107  {
108  return $this->processWithLockTarget($path, $value, $scope, $scopeCode, $lock);
109  }
110 
124  public function processWithLockTarget(
125  $path,
126  $value,
127  $scope,
128  $scopeCode,
129  $lock,
130  $lockTarget = ConfigFilePool::APP_ENV
131  ) {
132  try {
133  $this->scopeValidator->isValid($scope, $scopeCode);
134  $this->pathValidator->validate($path);
135  } catch (LocalizedException $exception) {
136  throw new ValidatorException(__($exception->getMessage()), $exception);
137  }
138 
139  $processor =
140  $lock
141  ? ( $lockTarget == ConfigFilePool::APP_ENV
142  ? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
143  : $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_CONFIG)
144  )
145  : $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT)
146  ;
147 
148  $message =
149  $lock
150  ? ( $lockTarget == ConfigFilePool::APP_ENV
151  ? 'Value was saved in app/etc/env.php and locked.'
152  : 'Value was saved in app/etc/config.php and locked.'
153  )
154  : 'Value was saved.';
155 
156  // The processing flow depends on --lock and --share options.
157  $processor->process($path, $value, $scope, $scopeCode);
158 
159  $this->hash->regenerate(System::CONFIG_TYPE);
160 
161  if ($this->scopeConfig instanceof Config) {
162  $this->scopeConfig->clean();
163  }
164 
165  return $message;
166  }
167 }
$processor
Definition: 404.php:10
__construct(ValidatorInterface $scopeValidator, PathValidator $pathValidator, ConfigSetProcessorFactory $configSetProcessorFactory, Hash $hash, ScopeConfigInterface $scopeConfig)
__()
Definition: __.php:13
$message
$value
Definition: gender.phtml:16
process($path, $value, $scope, $scopeCode, $lock)
processWithLockTarget( $path, $value, $scope, $scopeCode, $lock, $lockTarget=ConfigFilePool::APP_ENV)