Skip to content

[FrameworkBundle] Always display service arguments & deprecate --show-arguments option for debug:container #59225

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

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions UPGRADE-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FrameworkBundle

* Not setting the `framework.property_info.with_constructor_extractor` option explicitly is deprecated
because its default value will change in version 8.0
* Deprecate the `--show-arguments` option of the `container:debug` command, as arguments are now always shown

Serializer
----------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
* Rename `TranslationUpdateCommand` to `TranslationExtractCommand`
* Add JsonEncoder services and configuration
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
* Deprecate the `--show-arguments` option of the `container:debug` command, as arguments are now always shown

7.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$tag = $this->findProperTagName($input, $errorIo, $object, $tag);
$options = ['tag' => $tag];
} elseif ($name = $input->getArgument('name')) {
if ($input->getOption('show-arguments')) {
$errorIo->warning('The "--show-arguments" option is deprecated.');
}

$name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden'));
$options = ['id' => $name];
} elseif ($input->getOption('deprecations')) {
Expand All @@ -161,7 +165,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$helper = new DescriptorHelper();
$options['format'] = $input->getOption('format');
$options['show_arguments'] = $input->getOption('show-arguments');
$options['show_hidden'] = $input->getOption('show-hidden');
$options['raw_text'] = $input->getOption('raw');
$options['output'] = $io;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function describeContainerTags(ContainerBuilder $container, array $opt
foreach ($this->findDefinitionsByTag($container, $showHidden) as $tag => $definitions) {
$data[$tag] = [];
foreach ($definitions as $definition) {
$data[$tag][] = $this->getContainerDefinitionData($definition, true, false, $container, $options['id'] ?? null);
$data[$tag][] = $this->getContainerDefinitionData($definition, true, $container, $options['id'] ?? null);
}
}

Expand All @@ -79,7 +79,7 @@ protected function describeContainerService(object $service, array $options = []
if ($service instanceof Alias) {
$this->describeContainerAlias($service, $options, $container);
} elseif ($service instanceof Definition) {
$this->writeData($this->getContainerDefinitionData($service, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'], $container, $options['id']), $options);
$this->writeData($this->getContainerDefinitionData($service, isset($options['omit_tags']) && $options['omit_tags'], $container, $options['id']), $options);
} else {
$this->writeData($service::class, $options);
}
Expand All @@ -92,7 +92,6 @@ protected function describeContainerServices(ContainerBuilder $container, array
: $this->sortServiceIds($container->getServiceIds());
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
$omitTags = isset($options['omit_tags']) && $options['omit_tags'];
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
$data = ['definitions' => [], 'aliases' => [], 'services' => []];

if (isset($options['filter'])) {
Expand All @@ -112,7 +111,7 @@ protected function describeContainerServices(ContainerBuilder $container, array
if ($service->hasTag('container.excluded')) {
continue;
}
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments, $container, $serviceId);
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $container, $serviceId);
} else {
$data['services'][$serviceId] = $service::class;
}
Expand All @@ -123,7 +122,7 @@ protected function describeContainerServices(ContainerBuilder $container, array

protected function describeContainerDefinition(Definition $definition, array $options = [], ?ContainerBuilder $container = null): void
{
$this->writeData($this->getContainerDefinitionData($definition, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'], $container, $options['id'] ?? null), $options);
$this->writeData($this->getContainerDefinitionData($definition, isset($options['omit_tags']) && $options['omit_tags'], $container, $options['id'] ?? null), $options);
}

protected function describeContainerAlias(Alias $alias, array $options = [], ?ContainerBuilder $container = null): void
Expand All @@ -135,7 +134,7 @@ protected function describeContainerAlias(Alias $alias, array $options = [], ?Co
}

$this->writeData(
[$this->getContainerAliasData($alias), $this->getContainerDefinitionData($container->getDefinition((string) $alias), isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'], $container, (string) $alias)],
[$this->getContainerAliasData($alias), $this->getContainerDefinitionData($container->getDefinition((string) $alias), isset($options['omit_tags']) && $options['omit_tags'], $container, (string) $alias)],
array_merge($options, ['id' => (string) $alias])
);
}
Expand Down Expand Up @@ -245,7 +244,7 @@ protected function sortParameters(ParameterBag $parameters): array
return $sortedParameters;
}

private function getContainerDefinitionData(Definition $definition, bool $omitTags = false, bool $showArguments = false, ?ContainerBuilder $container = null, ?string $id = null): array
private function getContainerDefinitionData(Definition $definition, bool $omitTags = false, ?ContainerBuilder $container = null, ?string $id = null): array
{
$data = [
'class' => (string) $definition->getClass(),
Expand All @@ -269,9 +268,7 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
$data['description'] = $classDescription;
}

if ($showArguments) {
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments, $container, $id);
}
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $container, $id);

$data['file'] = $definition->getFile();

Expand Down Expand Up @@ -418,12 +415,12 @@ private function getCallableData(mixed $callable): array
throw new \InvalidArgumentException('Callable is not describable.');
}

private function describeValue($value, bool $omitTags, bool $showArguments, ?ContainerBuilder $container = null, ?string $id = null): mixed
private function describeValue($value, bool $omitTags, ?ContainerBuilder $container = null, ?string $id = null): mixed
{
if (\is_array($value)) {
$data = [];
foreach ($value as $k => $v) {
$data[$k] = $this->describeValue($v, $omitTags, $showArguments, $container, $id);
$data[$k] = $this->describeValue($v, $omitTags, $container, $id);
}

return $data;
Expand All @@ -445,11 +442,11 @@ private function describeValue($value, bool $omitTags, bool $showArguments, ?Con
}

if ($value instanceof ArgumentInterface) {
return $this->describeValue($value->getValues(), $omitTags, $showArguments, $container, $id);
return $this->describeValue($value->getValues(), $omitTags, $container, $id);
}

if ($value instanceof Definition) {
return $this->getContainerDefinitionData($value, $omitTags, $showArguments, $container, $id);
return $this->getContainerDefinitionData($value, $omitTags, $container, $id);
}

return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ protected function describeContainerServices(ContainerBuilder $container, array
$serviceIds = isset($options['tag']) && $options['tag']
? $this->sortTaggedServicesByPriority($container->findTaggedServiceIds($options['tag']))
: $this->sortServiceIds($container->getServiceIds());
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
$services = ['definitions' => [], 'aliases' => [], 'services' => []];

if (isset($options['filter'])) {
Expand Down Expand Up @@ -185,7 +184,7 @@ protected function describeContainerServices(ContainerBuilder $container, array
$this->write("\n\nDefinitions\n-----------\n");
foreach ($services['definitions'] as $id => $service) {
$this->write("\n");
$this->describeContainerDefinition($service, ['id' => $id, 'show_arguments' => $showArguments], $container);
$this->describeContainerDefinition($service, ['id' => $id], $container);
}
}

Expand Down Expand Up @@ -231,9 +230,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
$output .= "\n".'- Deprecated: no';
}

if (isset($options['show_arguments']) && $options['show_arguments']) {
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');
}
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');

if ($definition->getFile()) {
$output .= "\n".'- File: `'.$definition->getFile().'`';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
}
}

$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
$argumentsInformation = [];
if ($showArguments && ($arguments = $definition->getArguments())) {
if ($arguments = $definition->getArguments()) {
foreach ($arguments as $argument) {
if ($argument instanceof ServiceClosureArgument) {
$argument = $argument->getValues()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ protected function describeContainerService(object $service, array $options = []
throw new \InvalidArgumentException('An "id" option must be provided.');
}

$this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $container, isset($options['show_arguments']) && $options['show_arguments']));
$this->writeDocument($this->getContainerServiceDocument($service, $options['id'], $container));
}

protected function describeContainerServices(ContainerBuilder $container, array $options = []): void
{
$this->writeDocument($this->getContainerServicesDocument($container, $options['tag'] ?? null, isset($options['show_hidden']) && $options['show_hidden'], isset($options['show_arguments']) && $options['show_arguments'], $options['filter'] ?? null));
$this->writeDocument($this->getContainerServicesDocument($container, $options['tag'] ?? null, isset($options['show_hidden']) && $options['show_hidden'], $options['filter'] ?? null));
}

protected function describeContainerDefinition(Definition $definition, array $options = [], ?ContainerBuilder $container = null): void
{
$this->writeDocument($this->getContainerDefinitionDocument($definition, $options['id'] ?? null, isset($options['omit_tags']) && $options['omit_tags'], isset($options['show_arguments']) && $options['show_arguments'], $container));
$this->writeDocument($this->getContainerDefinitionDocument($definition, $options['id'] ?? null, isset($options['omit_tags']) && $options['omit_tags'], $container));
}

protected function describeContainerAlias(Alias $alias, array $options = [], ?ContainerBuilder $container = null): void
Expand All @@ -83,7 +83,7 @@ protected function describeContainerAlias(Alias $alias, array $options = [], ?Co
return;
}

$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($container->getDefinition((string) $alias), (string) $alias, false, false, $container)->childNodes->item(0), true));
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($container->getDefinition((string) $alias), (string) $alias, false, $container)->childNodes->item(0), true));

$this->writeDocument($dom);
}
Expand Down Expand Up @@ -260,25 +260,25 @@ private function getContainerTagsDocument(ContainerBuilder $container, bool $sho
$tagXML->setAttribute('name', $tag);

foreach ($definitions as $serviceId => $definition) {
$definitionXML = $this->getContainerDefinitionDocument($definition, $serviceId, true, false, $container);
$definitionXML = $this->getContainerDefinitionDocument($definition, $serviceId, true, $container);
$tagXML->appendChild($dom->importNode($definitionXML->childNodes->item(0), true));
}
}

return $dom;
}

private function getContainerServiceDocument(object $service, string $id, ?ContainerBuilder $container = null, bool $showArguments = false): \DOMDocument
private function getContainerServiceDocument(object $service, string $id, ?ContainerBuilder $container = null): \DOMDocument
{
$dom = new \DOMDocument('1.0', 'UTF-8');

if ($service instanceof Alias) {
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($service, $id)->childNodes->item(0), true));
if ($container) {
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($container->getDefinition((string) $service), (string) $service, false, $showArguments, $container)->childNodes->item(0), true));
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($container->getDefinition((string) $service), (string) $service, false, $container)->childNodes->item(0), true));
}
} elseif ($service instanceof Definition) {
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id, false, $showArguments, $container)->childNodes->item(0), true));
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($service, $id, false, $container)->childNodes->item(0), true));
} else {
$dom->appendChild($serviceXML = $dom->createElement('service'));
$serviceXML->setAttribute('id', $id);
Expand All @@ -288,7 +288,7 @@ private function getContainerServiceDocument(object $service, string $id, ?Conta
return $dom;
}

private function getContainerServicesDocument(ContainerBuilder $container, ?string $tag = null, bool $showHidden = false, bool $showArguments = false, ?callable $filter = null): \DOMDocument
private function getContainerServicesDocument(ContainerBuilder $container, ?string $tag = null, bool $showHidden = false, ?callable $filter = null): \DOMDocument
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($containerXML = $dom->createElement('container'));
Expand All @@ -311,14 +311,14 @@ private function getContainerServicesDocument(ContainerBuilder $container, ?stri
continue;
}

$serviceXML = $this->getContainerServiceDocument($service, $serviceId, null, $showArguments);
$serviceXML = $this->getContainerServiceDocument($service, $serviceId, null);
$containerXML->appendChild($containerXML->ownerDocument->importNode($serviceXML->childNodes->item(0), true));
}

return $dom;
}

private function getContainerDefinitionDocument(Definition $definition, ?string $id = null, bool $omitTags = false, bool $showArguments = false, ?ContainerBuilder $container = null): \DOMDocument
private function getContainerDefinitionDocument(Definition $definition, ?string $id = null, bool $omitTags = false, ?ContainerBuilder $container = null): \DOMDocument
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($serviceXML = $dom->createElement('definition'));
Expand Down Expand Up @@ -378,10 +378,8 @@ private function getContainerDefinitionDocument(Definition $definition, ?string
}
}

if ($showArguments) {
foreach ($this->getArgumentNodes($definition->getArguments(), $dom, $container) as $node) {
$serviceXML->appendChild($node);
}
foreach ($this->getArgumentNodes($definition->getArguments(), $dom, $container) as $node) {
$serviceXML->appendChild($node);
}

if (!$omitTags) {
Expand Down Expand Up @@ -443,7 +441,7 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom, ?Containe
$argumentXML->appendChild($childArgumentXML);
}
} elseif ($argument instanceof Definition) {
$argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true, $container)->childNodes->item(0), true));
$argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, $container)->childNodes->item(0), true));
} elseif ($argument instanceof AbstractArgument) {
$argumentXML->setAttribute('type', 'abstract');
$argumentXML->appendChild(new \DOMText($argument->getText()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function getDescribeContainerDefinitionTestData(): array
/** @dataProvider getDescribeContainerDefinitionWithArgumentsShownTestData */
public function testDescribeContainerDefinitionWithArgumentsShown(Definition $definition, $expectedDescription)
{
$this->assertDescription($expectedDescription, $definition, ['show_arguments' => true]);
$this->assertDescription($expectedDescription, $definition, []);
}

public static function getDescribeContainerDefinitionWithArgumentsShownTestData(): array
Expand Down Expand Up @@ -307,7 +307,7 @@ private static function getContainerBuilderDescriptionTestData(array $objects):
'public' => ['show_hidden' => false],
'tag1' => ['show_hidden' => true, 'tag' => 'tag1'],
'tags' => ['group_by' => 'tags', 'show_hidden' => true],
'arguments' => ['show_hidden' => false, 'show_arguments' => true],
'arguments' => ['show_hidden' => false],
];

$data = [];
Expand Down
Loading
Loading