X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FEventSubscriber%2FShowGenerateInlineListener.php;fp=vendor%2Fdrupal%2Fconsole-core%2Fsrc%2FEventSubscriber%2FShowGenerateInlineListener.php;h=90ea4b225a07ace732448dde0170ef86c2cd85ca;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/drupal/console-core/src/EventSubscriber/ShowGenerateInlineListener.php b/vendor/drupal/console-core/src/EventSubscriber/ShowGenerateInlineListener.php new file mode 100644 index 000000000..90ea4b225 --- /dev/null +++ b/vendor/drupal/console-core/src/EventSubscriber/ShowGenerateInlineListener.php @@ -0,0 +1,162 @@ +translator = $translator; + } + + /** + * @param ConsoleTerminateEvent $event + */ + public function showGenerateInline(ConsoleTerminateEvent $event) + { + if ($event->getExitCode() != 0) { + return; + } + + /* @var Command $command */ + $command = $event->getCommand(); + /* @var DrupalStyle $io */ + $io = new DrupalStyle($event->getInput(), $event->getOutput()); + + $command_name = $command->getName(); + + $this->skipArguments[] = $command_name; + + if (in_array($command->getName(), $this->skipCommands)) { + return; + } + + $input = $event->getInput(); + if ($input->getOption('generate-inline')) { + $options = array_filter($input->getOptions()); + foreach ($this->skipOptions as $remove_option) { + unset($options[$remove_option]); + } + + $arguments = array_filter($input->getArguments()); + foreach ($this->skipArguments as $remove_argument) { + unset($arguments[$remove_argument]); + } + + $inline = ''; + foreach ($arguments as $argument_id => $argument) { + if (is_array($argument)) { + $argument = implode(" ", $argument); + } elseif (strstr($argument, ' ')) { + $argument = '"' . $argument . '"'; + } + + $inline .= " $argument"; + } + + // Refactor and remove nested levels. Then apply to arguments. + foreach ($options as $optionName => $optionValue) { + if (is_array($optionValue)) { + foreach ($optionValue as $optionItem) { + if (is_array($optionItem)) { + $inlineValue = implode( + ' ', array_map( + function ($v, $k) { + return $k . ':' . $v; + }, + $optionItem, + array_keys($optionItem) + ) + ); + } else { + $inlineValue = $optionItem; + } + $inline .= ' --' . $optionName . '="' . $inlineValue . '"'; + } + } else { + if (is_bool($optionValue)) { + $inline.= ' --' . $optionName; + } else { + $inline.= ' --' . $optionName . '="' . $optionValue . '"'; + } + } + } + + // Print YML output and message + $io->commentBlock( + $this->translator->trans('application.messages.inline.generated') + ); + + $io->writeln( + sprintf( + '$ drupal %s %s', + $command_name, + $inline + ) + ); + } + } + + /** + * @{@inheritdoc} + */ + public static function getSubscribedEvents() + { + return [ConsoleEvents::TERMINATE => 'showGenerateInline']; + } +}