From 71d16526dc63b29f8e431f9ba30554a072ba7f8f Mon Sep 17 00:00:00 2001 From: Jesus Manuel Olivas Date: Thu, 23 Nov 2017 11:42:42 -0800 Subject: [PATCH] [console] Relocate getData method to drupal-console-core. (#3607) --- src/Application.php | 166 -------------------------------------------- 1 file changed, 166 deletions(-) diff --git a/src/Application.php b/src/Application.php index def56bb98..d8b057e78 100644 --- a/src/Application.php +++ b/src/Application.php @@ -143,170 +143,4 @@ public function validateCommands() return; } - - public function getData() - { - $singleCommands = [ - 'about', - 'chain', - 'check', - 'exec', - 'help', - 'init', - 'list', - 'shell', - 'server' - ]; - - $languages = $this->container->get('console.configuration_manager') - ->getConfiguration() - ->get('application.languages'); - - $data = []; - foreach ($singleCommands as $singleCommand) { - $data['commands']['misc'][] = $this->commandData($singleCommand); - } - - $namespaces = array_filter( - $this->getNamespaces(), function ($item) { - return (strpos($item, ':')<=0); - } - ); - sort($namespaces); - array_unshift($namespaces, 'misc'); - - foreach ($namespaces as $namespace) { - $commands = $this->all($namespace); - usort( - $commands, function ($cmd1, $cmd2) { - return strcmp($cmd1->getName(), $cmd2->getName()); - } - ); - - foreach ($commands as $command) { - if (method_exists($command, 'getModule')) { - if ($command->getModule() == 'Console') { - $data['commands'][$namespace][] = $this->commandData( - $command->getName() - ); - } - } else { - $data['commands'][$namespace][] = $this->commandData( - $command->getName() - ); - } - } - } - - $input = $this->getDefinition(); - $options = []; - foreach ($input->getOptions() as $option) { - $options[] = [ - 'name' => $option->getName(), - 'description' => $this->trans('application.options.'.$option->getName()) - ]; - } - $arguments = []; - foreach ($input->getArguments() as $argument) { - $arguments[] = [ - 'name' => $argument->getName(), - 'description' => $this->trans('application.arguments.'.$argument->getName()) - ]; - } - - $data['application'] = [ - 'namespaces' => $namespaces, - 'options' => $options, - 'arguments' => $arguments, - 'languages' => $languages, - 'messages' => [ - 'title' => $this->trans('application.gitbook.messages.title'), - 'note' => $this->trans('application.gitbook.messages.note'), - 'note_description' => $this->trans('application.gitbook.messages.note-description'), - 'command' => $this->trans('application.gitbook.messages.command'), - 'options' => $this->trans('application.gitbook.messages.options'), - 'option' => $this->trans('application.gitbook.messages.option'), - 'details' => $this->trans('application.gitbook.messages.details'), - 'arguments' => $this->trans('application.gitbook.messages.arguments'), - 'argument' => $this->trans('application.gitbook.messages.argument'), - 'examples' => $this->trans('application.gitbook.messages.examples') - ], - 'examples' => [] - ]; - - return $data; - } - - private function commandData($commandName) - { - if (!$this->has($commandName)) { - return []; - } - - $command = $this->find($commandName); - - $input = $command->getDefinition(); - $options = []; - foreach ($input->getOptions() as $option) { - $options[$option->getName()] = [ - 'name' => $option->getName(), - 'description' => $this->trans($option->getDescription()), - ]; - } - - $arguments = []; - foreach ($input->getArguments() as $argument) { - $arguments[$argument->getName()] = [ - 'name' => $argument->getName(), - 'description' => $this->trans($argument->getDescription()), - ]; - } - - $commandKey = str_replace(':', '.', $command->getName()); - - $examples = []; - for ($i = 0; $i < 5; $i++) { - $description = sprintf( - 'commands.%s.examples.%s.description', - $commandKey, - $i - ); - $execution = sprintf( - 'commands.%s.examples.%s.execution', - $commandKey, - $i - ); - - if ($description != $this->trans($description)) { - $examples[] = [ - 'description' => $this->trans($description), - 'execution' => $this->trans($execution) - ]; - } else { - break; - } - } - - $data = [ - 'name' => $command->getName(), - 'description' => $command->getDescription(), - 'options' => $options, - 'arguments' => $arguments, - 'examples' => $examples, - 'aliases' => $command->getAliases(), - 'key' => $commandKey, - 'dashed' => str_replace(':', '-', $command->getName()), - 'messages' => [ - 'usage' => $this->trans('application.gitbook.messages.usage'), - 'options' => $this->trans('application.gitbook.messages.options'), - 'option' => $this->trans('application.gitbook.messages.option'), - 'details' => $this->trans('application.gitbook.messages.details'), - 'arguments' => $this->trans('application.gitbook.messages.arguments'), - 'argument' => $this->trans('application.gitbook.messages.argument'), - 'examples' => $this->trans('application.gitbook.messages.examples') - ], - ]; - - return $data; - } }