|
@@ -49,13 +49,7 @@ The <info>container:debug</info> displays all configured <comment>public</commen
|
|
|
|
|
|
<info>container:debug</info>
|
|
|
|
|
|
-You can also search for specific services using wildcards (*):
|
|
|
-
|
|
|
- <info>container:debug doctrine.*</info>
|
|
|
-
|
|
|
- <info>container:debug *event_manager</info>
|
|
|
-
|
|
|
-To get specific information about a service, use specify its name exactly:
|
|
|
+To get specific information about a service, specify its name:
|
|
|
|
|
|
<info>container:debug validator</info>
|
|
|
|
|
@@ -73,20 +67,23 @@ EOF
|
|
|
*/
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
{
|
|
|
- $filter = $input->getArgument('name');
|
|
|
+ $name = $input->getArgument('name');
|
|
|
|
|
|
$this->containerBuilder = $this->getContainerBuilder();
|
|
|
- $serviceIds = $this->filterServices($this->containerBuilder->getServiceIds(), $filter);
|
|
|
+ $serviceIds = $this->containerBuilder->getServiceIds();
|
|
|
+
|
|
|
+ // sort so that it reads like an index of services
|
|
|
+ asort($serviceIds);
|
|
|
|
|
|
- if (1 == count($serviceIds) && false === strpos($filter, '*')) {
|
|
|
- $this->outputService($output, $serviceIds[0]);
|
|
|
+ if ($name) {
|
|
|
+ $this->outputService($output, $name);
|
|
|
} else {
|
|
|
$showPrivate = $input->getOption('show-private');
|
|
|
- $this->outputServices($output, $serviceIds, $filter, $showPrivate);
|
|
|
+ $this->outputServices($output, $serviceIds, $showPrivate);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected function outputServices(OutputInterface $output, $serviceIds, $filter, $showPrivate = false)
|
|
|
+ protected function outputServices(OutputInterface $output, $serviceIds, $showPrivate = false)
|
|
|
{
|
|
|
// set the label to specify public or public+private
|
|
|
if ($showPrivate) {
|
|
@@ -95,9 +92,6 @@ EOF
|
|
|
$label = '<comment>Public</comment> services';
|
|
|
}
|
|
|
|
|
|
- if ($filter) {
|
|
|
- $label .= sprintf(' matching <info>%s</info>', $filter);
|
|
|
- }
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('container', $label));
|
|
|
|
|
|
// loop through to find get space needed and filter private services
|
|
@@ -215,74 +209,4 @@ EOF
|
|
|
// the service has been injected in some special way, just return the service
|
|
|
return $this->containerBuilder->get($serviceId);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Filters the given array of service ids by the given string filter:
|
|
|
- *
|
|
|
- * * An exact filter, "foo", will return *only* the "foo" service
|
|
|
- * * A wildcard filter, "foo*", will return all services matching the wildcard
|
|
|
- *
|
|
|
- * @param array $serviceIds The array of service ids
|
|
|
- * @param string $filter The given filter. If ending in *, a wildcard
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function filterServices($serviceIds, $filter, $onlyPublic = true)
|
|
|
- {
|
|
|
- // alphabetical so that this reads like an index of services
|
|
|
- asort($serviceIds);
|
|
|
-
|
|
|
- if (!$filter) {
|
|
|
- return $serviceIds;
|
|
|
- }
|
|
|
-
|
|
|
- $regex = $this->buildFilterRegularExpression($filter);
|
|
|
- $filteredIds = array();
|
|
|
- foreach ($serviceIds as $serviceId) {
|
|
|
- if (preg_match($regex, $serviceId)) {
|
|
|
- $filteredIds[] = $serviceId;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!$filteredIds) {
|
|
|
- // give a different message if the use was searching for an exact service
|
|
|
- if (false === strpos($filter, '*')) {
|
|
|
- $message = sprintf('The service "%s" does not exist.', $filter);
|
|
|
- } else {
|
|
|
- $message = sprintf('No services matched the pattern "%s"', $filter);
|
|
|
- }
|
|
|
-
|
|
|
- throw new \InvalidArgumentException($message);
|
|
|
- }
|
|
|
-
|
|
|
- return $filteredIds;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Given a string with wildcards denoted as asterisks (*), this returns
|
|
|
- * the regular expression that can be used to match on the string.
|
|
|
- *
|
|
|
- * For example, *foo* would equate to:
|
|
|
- *
|
|
|
- * /^(.+?)*foo(.+?)*$/
|
|
|
- *
|
|
|
- * @param string $filter The raw filter
|
|
|
- * @return string The regular expression
|
|
|
- */
|
|
|
- private function buildFilterRegularExpression($filter)
|
|
|
- {
|
|
|
- $regex = preg_quote(str_replace('*', '', $filter));
|
|
|
-
|
|
|
- // process the "front" wildcard
|
|
|
- if ('*' === substr($filter, 0, 1)) {
|
|
|
- $regex = '(.+?)*'.$regex;
|
|
|
- }
|
|
|
-
|
|
|
- // process the "end" wildcard
|
|
|
- if ('*' === substr($filter, -1, 1)) {
|
|
|
- $regex .= '(.+?)*';
|
|
|
- }
|
|
|
- $regex = sprintf('/^%s$/', $regex);
|
|
|
-
|
|
|
- return $regex;
|
|
|
- }
|
|
|
}
|