/** * @param ConsoleTerminateEvent $event */ public function showCompletedMessage(ConsoleTerminateEvent $event) { /** * @var \Drupal\AppConsole\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); $application = $command->getApplication(); $messageHelper = $application->getHelperSet()->get('message'); /* @var TranslatorHelper */ $translatorHelper = $application->getHelperSet()->get('translator'); $messageHelper->showMessages($output); if ($event->getExitCode() != 0) { return; } if (in_array($command->getName(), $this->skipCommands)) { return; } $completedMessageKey = 'application.console.messages.completed'; if ($command instanceof GeneratorCommand) { $completedMessageKey = 'application.console.messages.generated.completed'; } $completedMessage = $translatorHelper->trans($completedMessageKey); if ($completedMessage != $completedMessageKey) { $messageHelper->showMessage($output, $completedMessage); } }
/** * @param ConsoleTerminateEvent $e */ public function onTerminate(ConsoleTerminateEvent $e) { // For non-0 exit command, fire an ERROR event if ($e->getExitCode() != 0) { $this->dispatch(ConsoleEvent::ERROR, $e); } $this->dispatch(ConsoleEvent::TERMINATE, $e); }
/** * @param ConsoleTerminateEvent $event */ public function showGenerateInline(ConsoleTerminateEvent $event) { /** * @var \Drupal\AppConsole\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); $command_name = $command->getName(); $this->skipArguments[] = $command_name; $application = $command->getApplication(); $messageHelper = $application->getHelperSet()->get('message'); /** * @var TranslatorHelper */ $translatorHelper = $application->getHelperSet()->get('translator'); if ($event->getExitCode() != 0) { return; } if (in_array($command->getName(), $this->skipCommands)) { return; } // get the input instance $input = $event->getInput(); //Get options list $options = array_filter($input->getOptions()); if (isset($options['generate-inline']) && $options['generate-inline'] == 1) { // Remove unnecessary options foreach ($this->skipOptions as $remove_option) { unset($options[$remove_option]); } // Get argument list $arguments = array_filter($input->getArguments()); // Remove unnecessary arguments 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}"; } foreach ($options as $option_id => $option) { if (strstr($option, ' ')) { $option = '"' . $option . '"'; } $inline .= ' --' . $option_id . '=' . $option; } // Print yaml output and message $messageHelper->showMessage($output, $translatorHelper->trans('application.console.messages.inline.generated')); $output->writeln('$ drupal' . $inline); } }
/** * Log Abnormal exists for AcmPhp commands. * * @param ConsoleTerminateEvent $event */ public function onConsoleTerminate(ConsoleTerminateEvent $event) { if (0 === ($exitCode = $event->getExitCode())) { return; } if (!$this->isAcmePhpCommand($event->getCommand())) { return; } $this->logger->error('Command "{command}" exited with code "{exitCode}".', ['command' => $event->getCommand()->getName(), 'exitCode' => $exitCode]); }
/** * @param ConsoleTerminateEvent $event */ public function onConsoleTerminate(ConsoleTerminateEvent $event) { $statusCode = $event->getExitCode(); $command = $event->getCommand(); if ($statusCode === 0) { return; } if ($statusCode > 255) { $statusCode = 255; $event->setExitCode($statusCode); } $this->logger->warning(sprintf('Command `%s` exited with status code %d', $command->getName(), $statusCode)); }
/** * @param ConsoleTerminateEvent $event */ public function showTerminateMessages(ConsoleTerminateEvent $event) { /** * @var \Drupal\Console\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); $application = $command->getApplication(); $messageHelper = $application->getMessageHelper(); $messageHelper->showMessages($output); if ($event->getExitCode() != 0) { return; } }
/** * @param ConsoleTerminateEvent $event */ public function showTerminateMessages(ConsoleTerminateEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); if ($errorMessage = $application->getErrorMessage()) { $io->warning($errorMessage); } if ($event->getExitCode() != 0) { return; } }
/** * @param ConsoleTerminateEvent $event */ public function showGenerateChain(ConsoleTerminateEvent $event) { /** * @var \Drupal\Console\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); $command_name = $command->getName(); $this->skipArguments[] = $command_name; $application = $command->getApplication(); $messageHelper = $application->getHelperSet()->get('message'); /* @var TranslatorHelper */ $translatorHelper = $application->getHelperSet()->get('translator'); if ($event->getExitCode() != 0) { return; } if (in_array($command->getName(), $this->skipCommands)) { return; } // get the input instance $input = $event->getInput(); //Get options list $options = array_filter($input->getOptions()); if (isset($options['generate-chain']) && $options['generate-chain'] == 1) { // Remove unnecessary options foreach ($this->skipOptions as $remove_option) { unset($options[$remove_option]); } // Get argument list $arguments = array_filter($input->getArguments()); // Remove unnecessary arguments foreach ($this->skipArguments as $remove_argument) { unset($arguments[$remove_argument]); } $yaml = array(); $yaml[$command_name]['options'] = $options; $yaml[$command_name]['arguments'] = $arguments; $dumper = new Dumper(); $yaml = $dumper->dump($yaml, 10); // Print yaml output and message $messageHelper->showMessage($output, $translatorHelper->trans('application.console.messages.chain.generated')); $output->writeln($yaml); } }
/** * @param ConsoleTerminateEvent $event */ public function showGeneratedFiles(ConsoleTerminateEvent $event) { /** @var \Drupal\AppConsole\Command\Command $command */ $command = $event->getCommand(); $output = $event->getOutput(); $application = $command->getApplication(); $messageHelper = $application->getHelperSet()->get('message'); if ($event->getExitCode() != 0) { return; } if ('self-update' == $command->getName()) { return; } if ($command instanceof GeneratorCommand) { $files = $command->getGenerator()->getFiles(); if ($files) { $messageHelper->showGeneratedFiles($output, $files); } } }
/** * @param ConsoleTerminateEvent $event */ public function showGenerateChain(ConsoleTerminateEvent $event) { if ($event->getExitCode() != 0) { return; } /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $command_name = $command->getName(); $this->skipArguments[] = $command_name; $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); if (in_array($command->getName(), $this->skipCommands)) { return; } $input = $event->getInput(); if ($input->getOption('generate-chain')) { $commands = []; $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]); } $commands['commands'][0]['command'] = $command_name; if ($options) { $commands['commands'][0]['options'] = $options; } if ($arguments) { $commands['commands'][0]['arguments'] = $arguments; } $dumper = new Dumper(); $yml = $dumper->dump($commands, 10); $yml = str_replace(sprintf('\'%s\':', $command_name), sprintf(' - command: %s', $command_name), $yml); $io->commentBlock($translatorHelper->trans('application.messages.chain.generated')); $io->writeln($yml); } }
/** * @param ConsoleTerminateEvent $event */ public function showGeneratedFiles(ConsoleTerminateEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $application = $command->getApplication(); $showFileHelper = $application->getShowFileHelper(); if ($event->getExitCode() != 0) { return; } if ('self-update' == $command->getName()) { return; } if ($command instanceof GeneratorCommand) { $files = $command->getGenerator()->getFiles(); if ($files) { $showFileHelper->generatedFiles($io, $files); } } }
/** * @param ConsoleTerminateEvent $event */ public function showGenerateInline(ConsoleTerminateEvent $event) { /* @var Command $command */ $command = $event->getCommand(); /* @var DrupalStyle $io */ $io = $event->getOutput(); $command_name = $command->getName(); $this->skipArguments[] = $command_name; $application = $command->getApplication(); $translatorHelper = $application->getTranslator(); if ($event->getExitCode() != 0) { return; } 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 yaml output and message $io->commentBlock($translatorHelper->trans('application.messages.inline.generated')); $io->writeln(sprintf('$ drupal %s %s', $command_name, $inline)); } }