5 * Contains \Drupal\Console\Command\PluginDebugCommand.
8 namespace Drupal\Console\Command;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Input\InputArgument;
13 use Symfony\Component\Console\Command\Command;
14 use Symfony\Component\Yaml\Yaml;
15 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
21 * @package Drupal\Console\Command
23 class PluginDebugCommand extends Command
25 use ContainerAwareCommandTrait;
29 protected function configure()
31 $this->setName('plugin:debug')
32 ->setDescription($this->trans('commands.plugin.debug.description'))
33 ->setHelp($this->trans('commands.plugin.debug.help'))
36 InputArgument::OPTIONAL,
37 $this->trans('commands.plugin.debug.arguments.type')
41 InputArgument::OPTIONAL,
42 $this->trans('commands.plugin.debug.arguments.id')
49 protected function execute(InputInterface $input, OutputInterface $output)
51 $io = new DrupalStyle($input, $output);
53 $pluginType = $input->getArgument('type');
54 $pluginId = $input->getArgument('id');
56 // No plugin type specified, show a list of plugin types.
59 $this->trans('commands.plugin.debug.table-headers.plugin-type-name'),
60 $this->trans('commands.plugin.debug.table-headers.plugin-type-class')
63 $serviceDefinitions = $this->container
64 ->getParameter('console.service_definitions');
66 foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
67 if (strpos($serviceId, 'plugin.manager.') === 0) {
68 $serviceName = substr($serviceId, 15);
69 $tableRows[$serviceName] = [
71 $serviceDefinition->getClass()
77 $io->table($tableHeader, array_values($tableRows));
82 $service = $this->container->get('plugin.manager.' . $pluginType);
86 $this->trans('commands.plugin.debug.errors.plugin-type-not-found'),
93 // Valid plugin type specified, no ID specified, show list of instances.
96 $this->trans('commands.plugin.debug.table-headers.plugin-id'),
97 $this->trans('commands.plugin.debug.table-headers.plugin-class')
100 foreach ($service->getDefinitions() as $definition) {
101 $pluginId = $definition['id'];
102 $className = $definition['class'];
103 $tableRows[$pluginId] = [$pluginId, $className];
106 $io->table($tableHeader, array_values($tableRows));
110 // Valid plugin type specified, ID specified, show the definition.
111 $definition = $service->getDefinition($pluginId);
113 $this->trans('commands.plugin.debug.table-headers.definition-key'),
114 $this->trans('commands.plugin.debug.table-headers.definition-value')
117 foreach ($definition as $key => $value) {
118 if (is_object($value) && method_exists($value, '__toString')) {
119 $value = (string) $value;
120 } elseif (is_array($value) || is_object($value)) {
121 $value = Yaml::dump($value);
122 } elseif (is_bool($value)) {
123 $value = ($value) ? 'TRUE' : 'FALSE';
125 $tableRows[$key] = [$key, $value];
128 $io->table($tableHeader, array_values($tableRows));