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 c587b85

Browse filesBrowse files
Simperfitnoemi-salaun
authored andcommitted
[FrameworkBundle] add --deprecations on debug:container command
1 parent dbe37de commit c587b85
Copy full SHA for c587b85

File tree

8 files changed

+151
-0
lines changed
Filter options

8 files changed

+151
-0
lines changed

‎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
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` command to see compile-time deprecations.
1617

1718
5.0.0
1819
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ 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, 'To output the deprecations generated when compiling and warming the cache'),
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>
72+
73+
To see deprecations generated during container compilation and cache warmup, use the <info>--deprecations</info> flag:
74+
75+
<info>php %command.full_name% --deprecations</info>
7176
7277
To get specific information about a service, specify its name:
7378
@@ -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
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
+8Lines changed: 8 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;
@@ -132,6 +135,11 @@ abstract protected function describeContainerService($service, array $options =
132135
*/
133136
abstract protected function describeContainerServices(ContainerBuilder $builder, array $options = []);
134137

138+
/**
139+
* Describes container deprecations.
140+
*/
141+
abstract protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []);
142+
135143
/**
136144
* Describes a service definition.
137145
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
190190
throw new LogicException('Using the JSON format to debug environment variables is not supported.');
191191
}
192192

193+
/**
194+
* {@inheritdoc}
195+
*/
196+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
197+
{
198+
throw new LogicException('Using the JSON format to print the deprecations is not supported.');
199+
}
200+
193201
/**
194202
* Writes data as json.
195203
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ protected function describeContainerService($service, array $options = [], Conta
119119
}
120120
}
121121

122+
/**
123+
* {@inheritdoc}
124+
*/
125+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
126+
{
127+
throw new LogicException('Using the Markdown format to print the deprecations is not supported.');
128+
}
129+
122130
/**
123131
* {@inheritdoc}
124132
*/

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

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

377+
/**
378+
* {@inheritdoc}
379+
*/
380+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
381+
{
382+
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.cache_dir'), $builder->getParameter('kernel.container_class'));
383+
if (!file_exists($containerDeprecationFilePath)) {
384+
$options['output']->warning('The deprecation file does not exist, please try warming the cache first.');
385+
386+
return;
387+
}
388+
389+
$logs = unserialize(file_get_contents($containerDeprecationFilePath));
390+
if (0 === \count($logs)) {
391+
$options['output']->success('There are no deprecations in the logs!');
392+
393+
return;
394+
}
395+
396+
$formattedLogs = [];
397+
$remainingCount = 0;
398+
foreach ($logs as $log) {
399+
$formattedLogs[] = sprintf("%sx: %s \n in %s:%s", $log['count'], $log['message'], $log['file'], $log['line']);
400+
$remainingCount += $log['count'];
401+
}
402+
$options['output']->title(sprintf('Remaining deprecations (%s)', $remainingCount));
403+
$options['output']->listing($formattedLogs);
404+
}
405+
377406
/**
378407
* {@inheritdoc}
379408
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
142142
throw new LogicException('Using the XML format to debug environment variables is not supported.');
143143
}
144144

145+
/**
146+
* {@inheritdoc}
147+
*/
148+
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
149+
{
150+
throw new LogicException('Using the XML format to print the deprecations is not supported.');
151+
}
152+
145153
/**
146154
* Writes DOM document.
147155
*/

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php
+82Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,88 @@ public function testDescribeEnvVar()
136136
$this->assertStringContainsString(file_get_contents(__DIR__.'/Fixtures/describe_env_vars.txt'), $tester->getDisplay(true));
137137
}
138138

139+
public function testGetDeprecation()
140+
{
141+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
142+
$path = sprintf('%s/%sDeprecations.log', static::$kernel->getContainer()->getParameter('kernel.cache_dir'), static::$kernel->getContainer()->getParameter('kernel.container_class'));
143+
touch($path);
144+
file_put_contents($path, serialize([[
145+
'type' => 16384,
146+
'message' => 'The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.',
147+
'file' => '/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php',
148+
'line' => 17,
149+
'trace' => [[
150+
'file' => '/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php',
151+
'line' => 9,
152+
'function' => 'spl_autoload_call',
153+
]],
154+
'count' => 1,
155+
]]));
156+
$application = new Application(static::$kernel);
157+
$application->setAutoExit(false);
158+
159+
@unlink(static::$container->getParameter('debug.container.dump'));
160+
161+
$tester = new ApplicationTester($application);
162+
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
163+
164+
$this->assertSame(0, $tester->getStatusCode());
165+
$this->assertContains('Symfony\Bundle\FrameworkBundle\Controller\Controller', $tester->getDisplay());
166+
$this->assertContains('/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php', $tester->getDisplay());
167+
}
168+
169+
public function testGetDeprecationNone()
170+
{
171+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
172+
$path = sprintf('%s/%sDeprecations.log', static::$kernel->getContainer()->getParameter('kernel.cache_dir'), static::$kernel->getContainer()->getParameter('kernel.container_class'));
173+
touch($path);
174+
file_put_contents($path, serialize([]));
175+
176+
$application = new Application(static::$kernel);
177+
$application->setAutoExit(false);
178+
179+
@unlink(static::$container->getParameter('debug.container.dump'));
180+
181+
$tester = new ApplicationTester($application);
182+
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
183+
184+
$this->assertSame(0, $tester->getStatusCode());
185+
$this->assertContains('[OK] There are no deprecations in the logs!', $tester->getDisplay());
186+
}
187+
188+
public function testGetDeprecationNoFile(): void
189+
{
190+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
191+
$path = sprintf('%s/%sDeprecations.log', static::$kernel->getContainer()->getParameter('kernel.cache_dir'), static::$kernel->getContainer()->getParameter('kernel.container_class'));
192+
@unlink($path);
193+
194+
$application = new Application(static::$kernel);
195+
$application->setAutoExit(false);
196+
197+
@unlink(static::$container->getParameter('debug.container.dump'));
198+
199+
$tester = new ApplicationTester($application);
200+
$tester->run(['command' => 'debug:container', '--deprecations' => true]);
201+
202+
$this->assertSame(0, $tester->getStatusCode());
203+
$this->assertContains('[WARNING] The deprecation file does not exist', $tester->getDisplay());
204+
}
205+
206+
public function testGetDeprecationXml(): void
207+
{
208+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
209+
$application = new Application(static::$kernel);
210+
$application->setAutoExit(false);
211+
212+
@unlink(static::$container->getParameter('debug.container.dump'));
213+
214+
$tester = new ApplicationTester($application);
215+
$tester->run(['command' => 'debug:container', '--deprecations' => true, '--format' => 'xml']);
216+
217+
$this->assertSame(1, $tester->getStatusCode());
218+
$this->assertContains('Using the XML format to print the deprecations is not supported.', $tester->getDisplay());
219+
}
220+
139221
public function provideIgnoreBackslashWhenFindingService()
140222
{
141223
return [

0 commit comments

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