5 * Contains \Drupal\Console\Core\EventSubscriber\ValidateDependenciesListener.
8 namespace Drupal\Console\Core\EventSubscriber;
10 use Symfony\Component\Console\ConsoleEvents;
11 use Symfony\Component\Console\Event\ConsoleCommandEvent;
12 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Utils\ConfigurationManager;
15 use Drupal\Console\Core\Utils\TranslatorManagerInterface;
16 use Drupal\Console\Core\Style\DrupalStyle;
19 * Class ValidateExecutionListener
21 * @package Drupal\Console\Core\EventSubscriber
23 class ValidateExecutionListener implements EventSubscriberInterface
26 * @var TranslatorManagerInterface
28 protected $translator;
31 * @var ConfigurationManager
33 protected $configurationManager;
36 * ValidateExecutionListener constructor.
38 * @param TranslatorManagerInterface $translator
39 * @param ConfigurationManager $configurationManager
41 public function __construct(
42 TranslatorManagerInterface $translator,
43 ConfigurationManager $configurationManager
45 $this->translator = $translator;
46 $this->configurationManager = $configurationManager;
50 * @param ConsoleCommandEvent $event
52 public function validateExecution(ConsoleCommandEvent $event)
54 /* @var Command $command */
55 $command = $event->getCommand();
56 /* @var DrupalStyle $io */
57 $io = new DrupalStyle($event->getInput(), $event->getOutput());
59 $configuration = $this->configurationManager->getConfiguration();
61 $mapping = $configuration->get('application.disable.commands')?:[];
62 if (array_key_exists($command->getName(), $mapping)) {
63 $extra = $mapping[$command->getName()];
65 $this->translator->trans('application.messages.disable.command.error'),
70 $this->translator->trans('application.messages.disable.command.extra'),
74 $io->commentBlock($message);
81 public static function getSubscribedEvents()
83 return [ConsoleEvents::COMMAND => 'validateExecution'];