protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $yaml = new Parser(); $dumper = new Dumper(); $yaml_file = $input->getArgument('yaml-file'); $yaml_key = $input->getArgument('yaml-key'); $yaml_new_key = $input->getArgument('yaml-new-key'); try { $yaml_parsed = $yaml->parse(file_get_contents($yaml_file)); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-parsing') . ': ' . $e->getMessage()); return; } if (empty($yaml_parsed)) { $io->info(sprintf($this->trans('commands.yaml.merge.messages.wrong-parse'), $yaml_file)); } $parents = explode(".", $yaml_key); $this->nestedArray->replaceKey($yaml_parsed, $parents, $yaml_new_key); try { $yaml = $dumper->dump($yaml_parsed, 10); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-generating') . ': ' . $e->getMessage()); return; } try { file_put_contents($yaml_file, $yaml); } catch (\Exception $e) { $io->error($this->trans('commands.yaml.merge.messages.error-writing') . ': ' . $e->getMessage()); return; } $io->info(sprintf($this->trans('commands.yaml.update.value.messages.updated'), $yaml_file)); }