5 * Contains \Drupal\Console\Command\ContainerDebugCommand.
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\Input\InputOption;
14 use Symfony\Component\Console\Command\Command;
15 use Symfony\Component\Yaml\Yaml;
16 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
20 * Class ContainerDebugCommand
22 * @package Drupal\Console\Command
24 class ContainerDebugCommand extends Command
26 use ContainerAwareCommandTrait;
31 protected function configure()
34 ->setName('container:debug')
35 ->setDescription($this->trans('commands.container.debug.description'))
39 InputOption::VALUE_NONE,
40 $this->trans('commands.container.debug.arguments.service')
44 InputArgument::OPTIONAL,
45 $this->trans('commands.container.debug.arguments.service')
52 protected function execute(InputInterface $input, OutputInterface $output)
54 $io = new DrupalStyle($input, $output);
55 $service = $input->getArgument('service');
56 $parameters = $input->getOption('parameters');
59 $parameterList = $this->getParameterList();
60 ksort($parameterList);
61 $io->write(Yaml::dump(['parameters' => $parameterList], 4, 2));
68 $tableRows = $this->getServiceDetail($service);
69 $io->table($tableHeader, $tableRows, 'compact');
75 $this->trans('commands.container.debug.messages.service_id'),
76 $this->trans('commands.container.debug.messages.class_name')
79 $tableRows = $this->getServiceList();
80 $io->table($tableHeader, $tableRows, 'compact');
85 private function getServiceList()
88 $serviceDefinitions = $this->container
89 ->getParameter('console.service_definitions');
91 foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
92 $services[] = [$serviceId, $serviceDefinition->getClass()];
97 private function getServiceDetail($service)
99 $serviceInstance = $this->get($service);
102 if ($serviceInstance) {
104 $this->trans('commands.container.debug.messages.service'),
108 $this->trans('commands.container.debug.messages.class'),
109 get_class($serviceInstance)
112 $this->trans('commands.container.debug.messages.interface'),
113 Yaml::dump(class_implements($serviceInstance))
115 if ($parent = get_parent_class($serviceInstance)) {
117 $this->trans('commands.container.debug.messages.parent'),
121 if ($vars = get_class_vars($serviceInstance)) {
123 $this->trans('commands.container.debug.messages.variables'),
127 if ($methods = get_class_methods($serviceInstance)) {
129 $this->trans('commands.container.debug.messages.methods'),
135 return $serviceDetail;
138 private function getParameterList()
140 $parameters = array_filter(
141 $this->container->getParameterBag()->all(), function ($name) {
142 if (preg_match('/^container\./', $name)) {
145 if (preg_match('/^drupal\./', $name)) {
148 if (preg_match('/^console\./', $name)) {
152 }, ARRAY_FILTER_USE_KEY