Skip to content

[WIP][FrameworkBundle] Use new table helper in container:debug command #8002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ protected function outputServices(OutputInterface $output, $serviceIds, $showPri

$output->writeln($this->getHelper('formatter')->formatSection('container', $label));

// loop through to get space needed and filter private services
$maxName = 4;
$maxScope = 6;
$maxTags = array();
$headerTags = array();
foreach ($serviceIds as $key => $serviceId) {
$definition = $this->resolveServiceDefinition($serviceId);

Expand All @@ -183,77 +180,52 @@ protected function outputServices(OutputInterface $output, $serviceIds, $showPri
continue;
}

if (strlen($definition->getScope()) > $maxScope) {
$maxScope = strlen($definition->getScope());
}

if (null !== $showTagAttributes) {
$tags = $definition->getTag($showTagAttributes);
foreach ($tags as $tag) {
foreach ($tag as $key => $value) {
if (!isset($maxTags[$key])) {
$maxTags[$key] = strlen($key);
}
if (strlen($value) > $maxTags[$key]) {
$maxTags[$key] = strlen($value);
foreach (array_keys($tag) as $key) {
if (!in_array($key, $headerTags, true)) {
$headerTags[] = $key;
}
}
}
}
}

if (strlen($serviceId) > $maxName) {
$maxName = strlen($serviceId);
}
}
$format = '%-'.$maxName.'s ';
$format .= implode("", array_map(function($length) { return "%-{$length}s "; }, $maxTags));
$format .= '%-'.$maxScope.'s %s';

// the title field needs extra space to make up for comment tags
$format1 = '%-'.($maxName + 19).'s ';
$format1 .= implode("", array_map(function($length) { return '%-'.($length + 19).'s '; }, $maxTags));
$format1 .= '%-'.($maxScope + 19).'s %s';

$tags = array();
foreach ($maxTags as $tagName => $length) {
$tags[] = '<comment>'.$tagName.'</comment>';
}
$output->writeln(vsprintf($format1, $this->buildArgumentsArray('<comment>Service Id</comment>', '<comment>Scope</comment>', '<comment>Class Name</comment>', $tags)));

$table = $this->getHelperSet()->get('table');
$table->setHeaders($this->buildArgumentsArray('Service Id', 'Scope', 'Class Name', $headerTags));

foreach ($serviceIds as $serviceId) {
$definition = $this->resolveServiceDefinition($serviceId);

if ($definition instanceof Definition) {
$lines = array();
if (null !== $showTagAttributes) {
foreach ($definition->getTag($showTagAttributes) as $key => $tag) {
$tagValues = array();
foreach (array_keys($maxTags) as $tagName) {
foreach ($headerTags as $tagName) {
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : "";
}
if (0 === $key) {
$lines[] = $this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass(), $tagValues);
$table->addRow($this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass(), $tagValues));
} else {
$lines[] = $this->buildArgumentsArray(' "', '', '', $tagValues);
$table->addRow($this->buildArgumentsArray(' "', '', '', $tagValues));
}
}
} else {
$lines[] = $this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass());
}

foreach ($lines as $arguments) {
$output->writeln(vsprintf($format, $arguments));
$table->addRow($this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass()));
}
} elseif ($definition instanceof Alias) {
$alias = $definition;
$output->writeln(vsprintf($format, $this->buildArgumentsArray($serviceId, 'n/a', sprintf('<comment>alias for</comment> <info>%s</info>', (string) $alias), count($maxTags) ? array_fill(0, count($maxTags), "") : array())));
$table->addRow($this->buildArgumentsArray($serviceId, 'n/a', sprintf('alias for %s', (string) $alias), count($headerTags) ? array_fill(0, count($headerTags), "") : array()));
} else {
// we have no information (happens with "service_container")
$service = $definition;
$output->writeln(vsprintf($format, $this->buildArgumentsArray($serviceId, '', get_class($service), count($maxTags) ? array_fill(0, count($maxTags), "") : array())));
$table->addRow($this->buildArgumentsArray($this->buildArgumentsArray($serviceId, '', get_class($service), count($headerTags) ? array_fill(0, count($headerTags), "") : array())));
}
}

$table->render($output);
}

protected function buildArgumentsArray($serviceId, $scope, $className, array $tagAttributes = array())
Expand Down