5 * Contains \Drupal\Console\Command\PluginDebugCommand.
8 namespace Drupal\Console\Command\Debug;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Input\InputArgument;
13 use Drupal\Console\Core\Command\ContainerAwareCommand;
14 use Symfony\Component\Yaml\Yaml;
19 * @package Drupal\Console\Command\Debug
21 class PluginCommand extends ContainerAwareCommand
26 protected function configure()
28 $this->setName('debug:plugin')
29 ->setDescription($this->trans('commands.debug.plugin.description'))
30 ->setHelp($this->trans('commands.debug.plugin.help'))
33 InputArgument::OPTIONAL,
34 $this->trans('commands.debug.plugin.arguments.type')
38 InputArgument::OPTIONAL,
39 $this->trans('commands.debug.plugin.arguments.id')
40 )->setAliases(['dpl']);
46 protected function execute(InputInterface $input, OutputInterface $output)
48 $pluginType = $input->getArgument('type');
49 $pluginId = $input->getArgument('id');
51 // No plugin type specified, show a list of plugin types.
54 $this->trans('commands.debug.plugin.table-headers.plugin-type-name'),
55 $this->trans('commands.debug.plugin.table-headers.plugin-type-class')
58 $serviceDefinitions = $this->container->getDefinitions();
60 foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
61 if (strpos($serviceId, 'plugin.manager.') === 0) {
62 $serviceName = substr($serviceId, 15);
63 $tableRows[$serviceName] = [
65 $serviceDefinition->getClass()
71 $this->getIo()->table($tableHeader, array_values($tableRows));
76 $service = $this->container->get('plugin.manager.' . $pluginType);
78 $this->getIo()->error(
80 $this->trans('commands.debug.plugin.errors.plugin-type-not-found'),
87 // Valid plugin type specified, no ID specified, show list of instances.
90 $this->trans('commands.debug.plugin.table-headers.plugin-id'),
91 $this->trans('commands.debug.plugin.table-headers.plugin-class')
94 foreach ($service->getDefinitions() as $definition) {
95 $pluginId = $definition['id'];
96 $className = $definition['class'];
97 $tableRows[$pluginId] = [$pluginId, $className];
100 $this->getIo()->table($tableHeader, array_values($tableRows));
104 // Valid plugin type specified, ID specified, show the definition.
105 $definition = $service->getDefinition($pluginId);
107 $this->trans('commands.debug.plugin.table-headers.definition-key'),
108 $this->trans('commands.debug.plugin.table-headers.definition-value')
111 foreach ($definition as $key => $value) {
112 if (is_object($value) && method_exists($value, '__toString')) {
113 $value = (string) $value;
114 } elseif (is_array($value) || is_object($value)) {
115 $value = Yaml::dump($value);
116 } elseif (is_bool($value)) {
117 $value = ($value) ? 'TRUE' : 'FALSE';
119 $tableRows[$key] = [$key, $value];
122 $this->getIo()->table($tableHeader, array_values($tableRows));