X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FContainerDebugCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FContainerDebugCommand.php;h=db128a41a3fd0024126abbe927a3eefd58f4f75c;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/ContainerDebugCommand.php b/vendor/drupal/console/src/Command/ContainerDebugCommand.php new file mode 100644 index 000000000..db128a41a --- /dev/null +++ b/vendor/drupal/console/src/Command/ContainerDebugCommand.php @@ -0,0 +1,157 @@ +setName('container:debug') + ->setDescription($this->trans('commands.container.debug.description')) + ->addOption( + 'parameters', + null, + InputOption::VALUE_NONE, + $this->trans('commands.container.debug.arguments.service') + ) + ->addArgument( + 'service', + InputArgument::OPTIONAL, + $this->trans('commands.container.debug.arguments.service') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $service = $input->getArgument('service'); + $parameters = $input->getOption('parameters'); + + if ($parameters) { + $parameterList = $this->getParameterList(); + ksort($parameterList); + $io->write(Yaml::dump(['parameters' => $parameterList], 4, 2)); + + return 0; + } + + $tableHeader = []; + if ($service) { + $tableRows = $this->getServiceDetail($service); + $io->table($tableHeader, $tableRows, 'compact'); + + return 0; + } + + $tableHeader = [ + $this->trans('commands.container.debug.messages.service_id'), + $this->trans('commands.container.debug.messages.class_name') + ]; + + $tableRows = $this->getServiceList(); + $io->table($tableHeader, $tableRows, 'compact'); + + return 0; + } + + private function getServiceList() + { + $services = []; + $serviceDefinitions = $this->container + ->getParameter('console.service_definitions'); + + foreach ($serviceDefinitions as $serviceId => $serviceDefinition) { + $services[] = [$serviceId, $serviceDefinition->getClass()]; + } + return $services; + } + + private function getServiceDetail($service) + { + $serviceInstance = $this->get($service); + $serviceDetail = []; + + if ($serviceInstance) { + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.service'), + $service + ]; + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.class'), + get_class($serviceInstance) + ]; + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.interface'), + Yaml::dump(class_implements($serviceInstance)) + ]; + if ($parent = get_parent_class($serviceInstance)) { + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.parent'), + $parent + ]; + } + if ($vars = get_class_vars($serviceInstance)) { + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.variables'), + Yaml::dump($vars) + ]; + } + if ($methods = get_class_methods($serviceInstance)) { + $serviceDetail[] = [ + $this->trans('commands.container.debug.messages.methods'), + Yaml::dump($methods) + ]; + } + } + + return $serviceDetail; + } + + private function getParameterList() + { + $parameters = array_filter( + $this->container->getParameterBag()->all(), function ($name) { + if (preg_match('/^container\./', $name)) { + return false; + } + if (preg_match('/^drupal\./', $name)) { + return false; + } + if (preg_match('/^console\./', $name)) { + return false; + } + return true; + }, ARRAY_FILTER_USE_KEY + ); + + return $parameters; + } +}