X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FCommand%2FYaml%2FUpdateValueCommand.php;fp=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FCommand%2FYaml%2FUpdateValueCommand.php;h=2e17cb73a84da73bfa5c8fc51c6d06bcbcf35dda;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console-core/src/Command/Yaml/UpdateValueCommand.php b/vendor/drupal/console-core/src/Command/Yaml/UpdateValueCommand.php new file mode 100644 index 000000000..2e17cb73a --- /dev/null +++ b/vendor/drupal/console-core/src/Command/Yaml/UpdateValueCommand.php @@ -0,0 +1,115 @@ +nestedArray = $nestedArray; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('yaml:update:value') + ->setDescription($this->trans('commands.yaml.update.value.description')) + ->addArgument( + 'yaml-file', + InputArgument::REQUIRED, + $this->trans('commands.yaml.update.value.arguments.yaml-file') + ) + ->addArgument( + 'yaml-key', + InputArgument::REQUIRED, + $this->trans('commands.yaml.update.value.arguments.yaml-key') + ) + ->addArgument( + 'yaml-value', + InputArgument::REQUIRED, + $this->trans('commands.yaml.update.value.arguments.yaml-value') + ); + } + + 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_value = $input->getArgument('yaml-value'); + + + 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->setValue($yaml_parsed, $parents, $yaml_value, true); + + 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 + ) + ); + } +}