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 6c8a088

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

File tree

8 files changed

+153
-2
lines changed
Filter options

8 files changed

+153
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CHANGELOG
2222
* Made `framework.session.handler_id` accept a DSN
2323
* Marked the `RouterDataCollector` class as `@final`.
2424
* [BC Break] The `framework.messenger.buses.<name>.middleware` config key is not deeply merged anymore.
25+
* Added `debug:container --deprecations` command to see compile-time deprecations
2526

2627
4.3.0
2728
-----
@@ -47,8 +48,8 @@ CHANGELOG
4748
options if you're using Symfony's serializer.
4849
* [BC Break] Removed the `framework.messenger.routing.send_and_handle` configuration.
4950
Instead of setting it to true, configure a `SyncTransport` and route messages to it.
50-
* Added information about deprecated aliases in `debug:autowiring`
51-
* Added php ini session options `sid_length` and `sid_bits_per_character`
51+
* Added information about deprecated aliases in `debug:autowiring`
52+
* Added php ini session options `sid_length` and `sid_bits_per_character`
5253
to the `session` section of the configuration
5354
* Added support for Translator paths, Twig paths in translation commands.
5455
* Added support for PHP files with translations in translation commands.

‎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
@@ -63,12 +63,17 @@ protected function configure()
6363
new InputOption('env-vars', null, InputOption::VALUE_NONE, 'Displays environment variables used in the container'),
6464
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
6565
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
66+
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'To output the deprecations generated when compiling and warming the cache'),
6667
])
6768
->setDescription('Displays current services for an application')
6869
->setHelp(<<<'EOF'
6970
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:
7071
7172
<info>php %command.full_name%</info>
73+
74+
To see deprecations generated during container compilation and cache warmup, use the <info>--deprecations</info> flag:
75+
76+
<info>php %command.full_name% --deprecations</info>
7277
7378
To get specific information about a service, specify its name:
7479
@@ -154,6 +159,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
154159
} elseif ($name = $input->getArgument('name')) {
155160
$name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden'));
156161
$options = ['id' => $name];
162+
} elseif ($input->getOption('deprecations')) {
163+
$options = ['deprecations' => true];
157164
} else {
158165
$options = [];
159166
}

‎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.