MageConfigSync\ConfigYaml::extractFromScopeKey PHP Method

extractFromScopeKey() public static method

public static extractFromScopeKey ( $scope_key ) : array
$scope_key
return array
    public static function extractFromScopeKey($scope_key)
    {
        $scope_key_parts = explode("-", $scope_key);
        $scope_key_parts_count = count($scope_key_parts);
        if ($scope_key_parts_count == 1) {
            $scope = $scope_key_parts[0];
            $scope_id = 0;
        } else {
            $scope = join("-", array_slice($scope_key_parts, 0, $scope_key_parts_count - 1));
            $scope_id = $scope_key_parts[$scope_key_parts_count - 1];
        }
        return array('scope' => $scope, 'scope_id' => $scope_id);
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Symfony\Component\Console\Output\ConsoleOutput $output */
     $magento = new Magento($input->getOption('magento-root'));
     $config_adapter = new ConfigurationAdapter($magento);
     $yaml = new Parser();
     if ($input->getArgument('config-yaml-file')) {
         $config_yaml_file = $input->getArgument('config-yaml-file');
         if (!file_exists($config_yaml_file)) {
             throw new \Exception("File ({$config_yaml_file}) does not exist");
         }
         if (!is_readable($config_yaml_file)) {
             throw new \Exception("File ({$config_yaml_file}) is not readable");
         }
         $config_file_contents = $yaml->parse(file_get_contents($config_yaml_file));
         $config_file_yaml = new ConfigYaml($config_file_contents, $input->getOption('env'));
         foreach ($config_file_yaml->getData() as $scope_key => $scope_data) {
             foreach ($scope_data as $path => $value) {
                 $scope_data = ConfigYaml::extractFromScopeKey($scope_key);
                 if ($value !== null) {
                     $affected_rows = $config_adapter->setValue($path, $value, $scope_data['scope'], $scope_data['scope_id']);
                 } else {
                     $affected_rows = $config_adapter->deleteValue($path, $scope_data['scope'], $scope_data['scope_id']);
                 }
                 if ($affected_rows > 0) {
                     $line = sprintf("[%s] %s -> %s", $scope_key, $path, $value ?: 'null');
                     if (method_exists($output, 'getErrorOutput')) {
                         $output->getErrorOutput()->writeln($line);
                     } else {
                         $output->writeln($line);
                     }
                 }
             }
         }
     }
     return 0;
 }