3 namespace Drupal\Console\Utils;
5 use Drupal\Console\Annotations\DrupalCommandAnnotationReader;
6 use Drupal\Console\Extension\Manager;
9 * Class AnnotationValidator
11 * @package Drupal\Console\Utils
13 class AnnotationValidator
16 * @var DrupalCommandAnnotationReader
18 protected $annotationCommandReader;
22 protected $extensionManager;
26 private $extensions = [];
29 * AnnotationValidator constructor.
31 * @param DrupalCommandAnnotationReader $annotationCommandReader
32 * @param Manager $extensionManager
34 public function __construct(
35 DrupalCommandAnnotationReader $annotationCommandReader,
36 Manager $extensionManager
38 $this->annotationCommandReader = $annotationCommandReader;
39 $this->extensionManager = $extensionManager;
46 public function isValidCommand($class)
48 $annotation = $this->annotationCommandReader->readAnnotation($class);
53 $dependencies = $this->extractDependencies($annotation);
59 foreach ($dependencies as $dependency) {
60 if (!$this->isExtensionInstalled($dependency)) {
72 protected function isExtensionInstalled($extension)
74 if (!$this->extensions) {
75 $modules = $this->extensionManager->discoverModules()
81 $themes = $this->extensionManager->discoverThemes()
87 $profiles = $this->extensionManager->discoverProfiles()
93 $this->extensions = array_merge(
100 return in_array($extension, $this->extensions);
107 protected function extractDependencies($annotation)
110 if (array_key_exists('extension', $annotation)) {
111 $dependencies[] = $annotation['extension'];
113 if (array_key_exists('dependencies', $annotation)) {
114 $dependencies = array_merge($dependencies, $annotation['dependencies']);
117 return $dependencies;