3 namespace Drupal\Console;
5 use Doctrine\Common\Annotations\AnnotationRegistry;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Output\OutputInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9 use Drupal\Console\Annotations\DrupalCommandAnnotationReader;
10 use Drupal\Console\Utils\AnnotationValidator;
11 use Drupal\Console\Core\Application as BaseApplication;
16 * @package Drupal\Console
18 class Application extends BaseApplication
23 const NAME = 'Drupal Console';
28 const VERSION = '1.8.0';
30 public function __construct(ContainerInterface $container)
32 parent::__construct($container, $this::NAME, $this::VERSION);
36 * Returns the long version of the application.
38 * @return string The long application version
40 public function getLongVersion()
44 if ('UNKNOWN' !== $this->getName()) {
45 if ('UNKNOWN' !== $this->getVersion()) {
46 $output .= sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());
48 $output .= sprintf('<info>%s</info>', $this->getName());
51 $output .= '<info>Drupal Console</info>';
60 public function doRun(InputInterface $input, OutputInterface $output)
62 $this->validateCommands();
64 return parent::doRun($input, $output);
67 public function validateCommands()
69 $consoleCommands = $this->container
70 ->findTaggedServiceIds('drupal.command');
72 if (!$consoleCommands) {
76 $serviceDefinitions = $this->container->getDefinitions();
78 if (!$serviceDefinitions) {
82 if (!$this->container->has('console.annotation_command_reader')) {
87 * @var DrupalCommandAnnotationReader $annotationCommandReader
89 $annotationCommandReader = $this->container
90 ->get('console.annotation_command_reader');
92 if (!$this->container->has('console.annotation_validator')) {
97 * @var AnnotationValidator $annotationValidator
99 $annotationValidator = $this->container
100 ->get('console.annotation_validator');
102 $invalidCommands = [];
104 foreach ($consoleCommands as $name => $tags) {
105 AnnotationRegistry::reset();
106 AnnotationRegistry::registerLoader(
108 $this->container->get('class_loader'),
113 if (!$this->container->has($name)) {
114 $invalidCommands[] = $name;
118 if (!$serviceDefinition = $serviceDefinitions[$name]) {
119 $invalidCommands[] = $name;
123 if (!$annotationValidator->isValidCommand(
124 $serviceDefinition->getClass()
127 $invalidCommands[] = $name;
131 $annotation = $annotationCommandReader
132 ->readAnnotation($serviceDefinition->getClass());
134 $this->container->get('console.translator_manager')
135 ->addResourceTranslationsByExtension(
136 $annotation['extension'],
137 $annotation['extensionType']
143 ->get('console.key_value_storage')
144 ->set('invalid_commands', $invalidCommands);