protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $yaml = new Parser(); $yaml_file = $input->getArgument('yaml-file'); $indent_level = $input->getOption('indent-level'); $exclude_parents_key = $input->getOption('exclude-parents-key'); $starting_key = $input->getOption('starting-key'); $file_output_prefix = $input->getOption('file-output-prefix'); $file_output_suffix = $input->getOption('file-output-suffix'); if ($exclude_parents_key == 1 || $exclude_parents_key == 'TRUE') { $exclude_parents_key = true; } else { $exclude_parents_key = false; } try { $yaml_file_parsed = $yaml->parse(file_get_contents($yaml_file)); if (empty($yaml_file_parsed)) { $io->error(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_file)); return; } } catch (\Exception $e) { $io->error(sprintf('%s: %s', $this->trans('commands.yaml.merge.messages.error-parsing'), $e->getMessage())); return; } if ($starting_key) { $parents = explode(".", $starting_key); if ($this->nestedArray->keyExists($yaml_file_parsed, $parents)) { $yaml_file_parsed = $this->nestedArray->getValue($yaml_file_parsed, $parents); } else { $io->error($this->trans('commands.yaml.merge.messages.invalid-key')); } if ($indent_level == 0) { $yaml_split[$starting_key] = $yaml_file_parsed; } } else { // Set minimum level to split $indent_level = empty($indent_level) ? 1 : $indent_level; $yaml_split = array(); $key_flatten = ''; $initial_level = 1; $this->nestedArray->yamlSplitArray($yaml_file_parsed, $yaml_split, $indent_level, $key_flatten, $initial_level, $exclude_parents_key); } $this->writeSplittedFile($yaml_split, $file_output_prefix, $file_output_suffix, $io); }