Skip to content

Commit 2cbed12

Browse files
committed
[FrameworkBundle] Add service and alias deprecation message to debug:container <name> output
1 parent 3c49bcf commit 2cbed12

File tree

59 files changed

+157
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+157
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
`Symfony\Component\Serializer\Normalizer\PropertyNormalizer` autowiring aliases, type-hint against
1111
`Symfony\Component\Serializer\Normalizer\NormalizerInterface` or implement `NormalizerAwareInterface` instead
1212
* Add service usages list to the `debug:container` command output
13+
* Add service and alias deprecation message to `debug:container [<name>]` output
1314

1415
6.1
1516
---

Command/ContainerDebugCommand.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
166166
try {
167167
$helper->describe($io, $object, $options);
168168

169+
if ('txt' === $options['format'] && isset($options['id'])) {
170+
if ($object->hasDefinition($options['id'])) {
171+
$definition = $object->getDefinition($options['id']);
172+
if ($definition->isDeprecated()) {
173+
$errorIo->warning($definition->getDeprecation($options['id'])['message'] ?? sprintf('The "%s" service is deprecated.', $options['id']));
174+
}
175+
}
176+
if ($object->hasAlias($options['id'])) {
177+
$alias = $object->getAlias($options['id']);
178+
if ($alias->isDeprecated()) {
179+
$errorIo->warning($alias->getDeprecation($options['id'])['message'] ?? sprintf('The "%s" alias is deprecated.', $options['id']));
180+
}
181+
}
182+
}
183+
169184
if (isset($options['id']) && isset($kernel->getContainer()->getRemovedIds()[$options['id']])) {
170185
$errorIo->note(sprintf('The "%s" service or alias has been removed or inlined when the container was compiled.', $options['id']));
171186
}

Console/Descriptor/JsonDescriptor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ private function getContainerDefinitionData(Definition $definition, bool $omitTa
230230
'autoconfigure' => $definition->isAutoconfigured(),
231231
];
232232

233+
if ($definition->isDeprecated()) {
234+
$data['deprecated'] = true;
235+
$data['deprecation_message'] = $definition->getDeprecation($id)['message'];
236+
} else {
237+
$data['deprecated'] = false;
238+
}
239+
233240
if ('' !== $classDescription = $this->getClassDescription((string) $definition->getClass())) {
234241
$data['description'] = $classDescription;
235242
}

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ protected function describeContainerDefinition(Definition $definition, array $op
211211
."\n".'- Autoconfigured: '.($definition->isAutoconfigured() ? 'yes' : 'no')
212212
;
213213

214+
if ($definition->isDeprecated()) {
215+
$output .= "\n".'- Deprecated: yes';
216+
$output .= "\n".'- Deprecation message: '.$definition->getDeprecation($options['id'])['message'];
217+
} else {
218+
$output .= "\n".'- Deprecated: no';
219+
}
220+
214221
if (isset($options['show_arguments']) && $options['show_arguments']) {
215222
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');
216223
}

Console/Descriptor/XmlDescriptor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ private function getContainerDefinitionDocument(Definition $definition, string $
341341
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
342342
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
343343
$serviceXML->setAttribute('autoconfigured', $definition->isAutoconfigured() ? 'true' : 'false');
344+
if ($definition->isDeprecated()) {
345+
$serviceXML->setAttribute('deprecated', 'true');
346+
$serviceXML->setAttribute('deprecation_message', $definition->getDeprecation($id)['message']);
347+
} else {
348+
$serviceXML->setAttribute('deprecated', 'false');
349+
}
344350
$serviceXML->setAttribute('file', $definition->getFile() ?? '');
345351

346352
$calls = $definition->getMethodCalls();

Tests/Fixtures/DeprecatedClass.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
4+
5+
/**
6+
* @deprecated
7+
*/
8+
class DeprecatedClass
9+
{
10+
}

Tests/Fixtures/Descriptor/alias_with_definition_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"abstract": true,
1313
"autowire": false,
1414
"autoconfigure": false,
15+
"deprecated": false,
1516
"file": null,
1617
"factory_class": "Full\\Qualified\\FactoryClass",
1718
"factory_method": "get",

Tests/Fixtures/Descriptor/alias_with_definition_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Abstract: yes
1414
- Autowired: no
1515
- Autoconfigured: no
16+
- Deprecated: no
1617
- Factory Class: `Full\Qualified\FactoryClass`
1718
- Factory Method: `get`
1819
- Usages: alias_1

Tests/Fixtures/Descriptor/alias_with_definition_1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<alias id="alias_1" service="service_1" public="true"/>
3-
<definition id="service_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" autoconfigured="false" file="">
3+
<definition id="service_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" autoconfigured="false" deprecated="false" file="">
44
<factory class="Full\Qualified\FactoryClass" method="get"/>
55
<usages>
66
<usage>alias_1</usage>

Tests/Fixtures/Descriptor/alias_with_definition_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"abstract": false,
1313
"autowire": false,
1414
"autoconfigure": false,
15+
"deprecated": false,
1516
"file": "\/path\/to\/file",
1617
"factory_service": "factory.service",
1718
"factory_method": "get",

0 commit comments

Comments
 (0)