Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultProcessor.php
Go to the documentation of this file.
1 <?php
7 
15 
25 {
31  private $deploymentConfig;
32 
38  private $configPathResolver;
39 
45  private $preparedValueFactory;
46 
52  public function __construct(
53  PreparedValueFactory $preparedValueFactory,
54  DeploymentConfig $deploymentConfig,
55  ConfigPathResolver $configPathResolver
56  ) {
57  $this->preparedValueFactory = $preparedValueFactory;
58  $this->deploymentConfig = $deploymentConfig;
59  $this->configPathResolver = $configPathResolver;
60  }
61 
69  public function process($path, $value, $scope, $scopeCode)
70  {
71  if ($this->isLocked($path, $scope, $scopeCode)) {
72  throw new CouldNotSaveException(
73  __(
74  'The value you set has already been locked. To change the value, use the --%1 option.',
76  )
77  );
78  }
79 
80  try {
82  $backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
83  if ($backendModel instanceof Value) {
84  $resourceModel = $backendModel->getResource();
85  $resourceModel->save($backendModel);
86  }
87  } catch (\Exception $exception) {
88  throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
89  }
90  }
91 
100  private function isLocked($path, $scope, $scopeCode)
101  {
102  $scopePath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
103 
104  return $this->deploymentConfig->get($scopePath) !== null;
105  }
106 }
__()
Definition: __.php:13
$deploymentConfig
__construct(PreparedValueFactory $preparedValueFactory, DeploymentConfig $deploymentConfig, ConfigPathResolver $configPathResolver)
$value
Definition: gender.phtml:16
$resourceModel
Definition: tablerates.php:10