Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d028a50

Browse filesBrowse files
feature #35995 [FrameworkBundle] add --deprecations on debug:container command (Simperfit, noemi-salaun)
This PR was merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] add --deprecations on debug:container command | Q | A | ------------- | --- | Branch? | master (5.1) | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | #30089 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | todo _I apologize in advance, I am not fluent in English_ Continuity of @Simperfit work from his PR #32584 I added support for XML, JSON and markdown formats as well as unit tests for all formats. ## XML format ```xml <?xml version="1.0" encoding="UTF-8"?> <deprecations remainingCount="5"> <deprecation count="3"> <message>Some deprecation message.</message> <file>/path/to/some/file.php</file> <line>39</line> </deprecation> <deprecation count="2"> <message>An other deprecation message.</message> <file>/path/to/an/other/file.php</file> <line>25</line> </deprecation> </deprecations> ``` ## JSON format ```json { "remainingCount": 5, "deprecations": [ { "message": "Some deprecation message.", "file": "\/path\/to\/some\/file.php", "line": 39, "count": 3 }, { "message": "An other deprecation message.", "file": "\/path\/to\/an\/other\/file.php", "line": 25, "count": 2 } ] } ``` ## Markdown format ## Remaining deprecations (5) - 3x: "Some deprecation message." in /path/to/some/file.php:39 - 2x: "An other deprecation message." in /path/to/an/other/file.php:25 I added a new commit on top of @Simperfit 's one, but I don't know how you would like to have the git history writed. Commits ------- ee6391e [FrameworkBundle] add all formats support for debug:container --deprecations command 161f659 [FrameworkBundle] add --deprecations on debug:container command
2 parents 66e53fb + ee6391e commit d028a50
Copy full SHA for d028a50

20 files changed

+275-1Lines changed: 275 additions & 1 deletion
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* The `TemplateController` now accepts context argument
1414
* Deprecated *not* setting the "framework.router.utf8" configuration option as it will default to `true` in Symfony 6.0
1515
* Added tag `routing.expression_language_function` to define functions available in route conditions
16+
* Added `debug:container --deprecations` option to see compile-time deprecations.
1617

1718
5.0.0
1819
-----
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ protected function configure()
6262
new InputOption('env-vars', null, InputOption::VALUE_NONE, 'Displays environment variables used in the container'),
6363
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
6464
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
65+
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'Displays deprecations generated when compiling and warming up the container'),
6566
])
6667
->setDescription('Displays current services for an application')
6768
->setHelp(<<<'EOF'
6869
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:
6970
7071
<info>php %command.full_name%</info>
7172
73+
To see deprecations generated during container compilation and cache warmup, use the <info>--deprecations</info> option:
74+
75+
<info>php %command.full_name% --deprecations</info>
76+
7277
To get specific information about a service, specify its name:
7378
7479
<info>php %command.full_name% validator</info>
@@ -149,6 +154,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149154
} elseif ($name = $input->getArgument('name')) {
150155
$name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden'));
151156
$options = ['id' => $name];
157+
} elseif ($input->getOption('deprecations')) {
158+
$options = ['deprecations' => true];
152159
} else {
153160
$options = [];
154161
}
@@ -180,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
180187
$errorIo->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
181188
} elseif ($input->getOption('parameters')) {
182189
$errorIo->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
183-
} else {
190+
} elseif (!$input->getOption('deprecations')) {
184191
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
185192
}
186193
}
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function describe(OutputInterface $output, $object, array $options = [])
6464
case $object instanceof ContainerBuilder && isset($options['parameter']):
6565
$this->describeContainerParameter($object->resolveEnvPlaceholders($object->getParameter($options['parameter'])), $options);
6666
break;
67+
case $object instanceof ContainerBuilder && isset($options['deprecations']):
68+
$this->describeContainerDeprecations($object, $options);
69+
break;
6770
case $object instanceof ContainerBuilder:
6871
$this->describeContainerServices($object, $options);
6972
break;
@@ -120,6 +123,8 @@ abstract protected function describeContainerService($service, array $options =
120123
*/
121124
abstract protected function describeContainerServices(ContainerBuilder $builder, array $options = []);
122125

126+
abstract protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void;
127+
123128
abstract protected function describeContainerDefinition(Definition $definition, array $options = []);
124129

125130
abstract protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null);
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1718
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -154,6 +155,30 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
154155
throw new LogicException('Using the JSON format to debug environment variables is not supported.');
155156
}
156157

158+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
159+
{
160+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
161+
if (!file_exists($containerDeprecationFilePath)) {
162+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
163+
}
164+
165+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
166+
167+
$formattedLogs = [];
168+
$remainingCount = 0;
169+
foreach ($logs as $log) {
170+
$formattedLogs[] = [
171+
'message' => $log['message'],
172+
'file' => $log['file'],
173+
'line' => $log['line'],
174+
'count' => $log['count'],
175+
];
176+
$remainingCount += $log['count'];
177+
}
178+
179+
$this->writeData(['remainingCount' => $remainingCount, 'deprecations' => $formattedLogs], $options);
180+
}
181+
157182
private function writeData(array $data, array $options)
158183
{
159184
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -104,6 +105,33 @@ protected function describeContainerService($service, array $options = [], Conta
104105
}
105106
}
106107

108+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
109+
{
110+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
111+
if (!file_exists($containerDeprecationFilePath)) {
112+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
113+
}
114+
115+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
116+
if (0 === \count($logs)) {
117+
$this->write("## There are no deprecations in the logs!\n");
118+
119+
return;
120+
}
121+
122+
$formattedLogs = [];
123+
$remainingCount = 0;
124+
foreach ($logs as $log) {
125+
$formattedLogs[] = sprintf("- %sx: \"%s\" in %s:%s\n", $log['count'], $log['message'], $log['file'], $log['line']);
126+
$remainingCount += $log['count'];
127+
}
128+
129+
$this->write(sprintf("## Remaining deprecations (%s)\n\n", $remainingCount));
130+
foreach ($formattedLogs as $formattedLog) {
131+
$this->write($formattedLog);
132+
}
133+
}
134+
107135
protected function describeContainerServices(ContainerBuilder $builder, array $options = [])
108136
{
109137
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,32 @@ protected function describeContainerDefinition(Definition $definition, array $op
353353
$options['output']->table($tableHeaders, $tableRows);
354354
}
355355

356+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
357+
{
358+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
359+
if (!file_exists($containerDeprecationFilePath)) {
360+
$options['output']->warning('The deprecation file does not exist, please try warming the cache first.');
361+
362+
return;
363+
}
364+
365+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
366+
if (0 === \count($logs)) {
367+
$options['output']->success('There are no deprecations in the logs!');
368+
369+
return;
370+
}
371+
372+
$formattedLogs = [];
373+
$remainingCount = 0;
374+
foreach ($logs as $log) {
375+
$formattedLogs[] = sprintf("%sx: %s\n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
376+
$remainingCount += $log['count'];
377+
}
378+
$options['output']->title(sprintf('Remaining deprecations (%s)', $remainingCount));
379+
$options['output']->listing($formattedLogs);
380+
}
381+
356382
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null)
357383
{
358384
if ($alias->isPublic()) {
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

1414
use Symfony\Component\Console\Exception\LogicException;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1718
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -106,6 +107,34 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
106107
throw new LogicException('Using the XML format to debug environment variables is not supported.');
107108
}
108109

110+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
111+
{
112+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
113+
if (!file_exists($containerDeprecationFilePath)) {
114+
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
115+
}
116+
117+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
118+
119+
$dom = new \DOMDocument('1.0', 'UTF-8');
120+
$dom->appendChild($deprecationsXML = $dom->createElement('deprecations'));
121+
122+
$formattedLogs = [];
123+
$remainingCount = 0;
124+
foreach ($logs as $log) {
125+
$deprecationsXML->appendChild($deprecationXML = $dom->createElement('deprecation'));
126+
$deprecationXML->setAttribute('count', $log['count']);
127+
$deprecationXML->appendChild($dom->createElement('message', $log['message']));
128+
$deprecationXML->appendChild($dom->createElement('file', $log['file']));
129+
$deprecationXML->appendChild($dom->createElement('line', $log['line']));
130+
$remainingCount += $log['count'];
131+
}
132+
133+
$deprecationsXML->setAttribute('remainingCount', $remainingCount);
134+
135+
$this->writeDocument($dom);
136+
}
137+
109138
private function writeDocument(\DOMDocument $dom)
110139
{
111140
$dom->formatOutput = true;
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ public function getClassDescriptionTestData()
211211
];
212212
}
213213

214+
/**
215+
* @dataProvider getDeprecationsTestData
216+
*/
217+
public function testGetDeprecations(ContainerBuilder $builder, $expectedDescription)
218+
{
219+
$this->assertDescription($expectedDescription, $builder, ['deprecations' => true]);
220+
}
221+
222+
public function getDeprecationsTestData()
223+
{
224+
return $this->getDescriptionTestData(ObjectsProvider::getContainerDeprecations());
225+
}
226+
214227
abstract protected function getDescriptor();
215228

216229
abstract protected function getFormat();
Collapse file

‎src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public static function getContainerParameter()
8888
];
8989
}
9090

91+
public static function getContainerDeprecations()
92+
{
93+
$builderWithDeprecations = new ContainerBuilder();
94+
$builderWithDeprecations->setParameter('kernel.cache_dir', __DIR__.'/../../Fixtures/Descriptor/cache');
95+
$builderWithDeprecations->setParameter('kernel.container_class', 'KernelContainerWith');
96+
97+
$builderWithoutDeprecations = new ContainerBuilder();
98+
$builderWithoutDeprecations->setParameter('kernel.cache_dir', __DIR__.'/../../Fixtures/Descriptor/cache');
99+
$builderWithoutDeprecations->setParameter('kernel.container_class', 'KernelContainerWithout');
100+
101+
return [
102+
'deprecations' => $builderWithDeprecations,
103+
'deprecations_empty' => $builderWithoutDeprecations,
104+
];
105+
}
106+
91107
public static function getContainerBuilders()
92108
{
93109
$builder1 = new ContainerBuilder();
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:2:{i:0;a:6:{s:4:"type";i:16384;s:7:"message";s:25:"Some deprecation message.";s:4:"file";s:22:"/path/to/some/file.php";s:4:"line";i:39;s:5:"trace";a:0:{}s:5:"count";i:3;}i:1;a:6:{s:4:"type";i:16384;s:7:"message";s:29:"An other deprecation message.";s:4:"file";s:26:"/path/to/an/other/file.php";s:4:"line";i:25;s:5:"trace";a:0:{}s:5:"count";i:2;}}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.