arrayUtils = $arrayUtils; $this->valueFactory = $valueBuilder; $this->scopeConfig = $scopeConfig; } /** * Emulates saving of data array. * * @param array $data The data to be saved * @return void */ public function process(array $data) { foreach ($data as $scope => $scopeData) { if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { $this->invokeSave($scopeData, $scope); } else { foreach ($scopeData as $scopeCode => $scopeCodeData) { $this->invokeSave($scopeCodeData, $scope, $scopeCode); } } } } /** * Emulates saving of configuration. * This is a temporary solution until Magento reworks * backend models for configurations. * * Example of $scopeData argument: * * ```php * [ * 'web' => [ * 'unsecure' => [ * 'base_url' => "http://magento2.local/" * ] * ] * ]; * ``` * * @param array $scopeData The data for specific scope * @param string $scope The configuration scope (default, website, or store) * @param string $scopeCode The scope code * @return void */ private function invokeSave(array $scopeData, $scope, $scopeCode = null) { $scopeData = array_keys($this->arrayUtils->flatten($scopeData)); foreach ($scopeData as $path) { $value = $this->scopeConfig->getValue($path, $scope, $scopeCode); $backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode); if ($backendModel instanceof Value) { $backendModel->beforeSave(); $backendModel->afterSave(); } } } }