X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FCommand%2FYaml%2FGetValueCommand.php;fp=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FCommand%2FYaml%2FGetValueCommand.php;h=a02634ebba45827096d9e1997ece6f3bf86cca5e;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console-core/src/Command/Yaml/GetValueCommand.php b/vendor/drupal/console-core/src/Command/Yaml/GetValueCommand.php new file mode 100644 index 000000000..a02634ebb --- /dev/null +++ b/vendor/drupal/console-core/src/Command/Yaml/GetValueCommand.php @@ -0,0 +1,96 @@ +nestedArray = $nestedArray; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('yaml:get:value') + ->setDescription($this->trans('commands.yaml.get.value.description')) + ->addArgument( + 'yaml-file', + InputArgument::REQUIRED, + $this->trans('commands.yaml.get.value.arguments.yaml-file') + ) + ->addArgument( + 'yaml-key', + InputArgument::REQUIRED, + $this->trans('commands.yaml.get.value.arguments.yaml-key') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $yaml = new Parser(); + + $yaml_file = $input->getArgument('yaml-file'); + $yaml_key = $input->getArgument('yaml-key'); + + try { + $yaml_parsed = $yaml->parse(file_get_contents($yaml_file), true); + } 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 + ) + ); + } else { + $key_exists = null; + $parents = explode(".", $yaml_key); + $yaml_value = $this->nestedArray->getValue($yaml_parsed, $parents, $key_exists); + + if (!$key_exists) { + $io->info( + sprintf( + $this->trans('commands.yaml.get.value.messages.invalid-key'), + $yaml_key, + $yaml_file + ) + ); + } + + $io->writeln($yaml_value); + } + } +}