+ /**
+ * registerExtendCommands
+ */
+ private function registerExtendCommands()
+ {
+ $this->container->get('console.configuration_manager')
+ ->loadExtendConfiguration();
+ }
+
+ public function getData()
+ {
+ $singleCommands = [
+ 'about',
+ 'chain',
+ 'check',
+ 'composerize',
+ '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;
+ }
+
+ /**
+ * @return DrupalInterface
+ */
+ public function getDrupal()
+ {
+ return $this->drupal;
+ }
+
+ /**
+ * @param DrupalInterface $drupal
+ */
+ public function setDrupal($drupal)
+ {
+ $this->drupal = $drupal;
+ }
+
+ public function setContainer($container)
+ {
+ $this->container = $container;
+ }
+
+ public function getContainer()
+ {
+ return $this->container;
+ }
+
+ /**
+ * Add Drupal system messages.
+ */
+ protected function addDrupalMessages($messageManager) {
+ if (function_exists('drupal_get_messages')) {
+ $drupalMessages = drupal_get_messages();
+ foreach ($drupalMessages as $type => $messages) {
+ foreach ($messages as $message) {
+ $method = $this->getMessageMethod($type);
+ $messageManager->{$method}((string)$message);
+ }
+ }
+ }
+ }
+
+ /**
+ * Gets method name for MessageManager.
+ *
+ * @param string $type
+ * Type of the message.
+ *
+ * @return string
+ * Name of the method
+ */
+ protected function getMessageMethod($type) {
+ $methodName = 'info';
+ switch ($type) {
+ case 'error':
+ case 'warning':
+ $methodName = $type;
+ break;
+ }
+
+ return $methodName;
+ }
+