Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc27ad7a

Browse files
committed
[FrameworkBundle] add debug:deprecations:warmed command
1 parent25f1804 commitc27ad7a

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* The`ControllerResolver` and`DelegatingLoader` classes have been marked as`final`
1111
* Added support for configuring chained cache pools
1212
* Deprecated booting the kernel before running`WebTestCase::createClient()`
13+
* Added the`DebugDeprecationsWarmedCommand` to show the deprecation in CLI.
1314

1415
4.3.0
1516
-----
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Command;
13+
14+
useSymfony\Component\Console\Command\Command;
15+
useSymfony\Component\Console\Input\InputInterface;
16+
useSymfony\Component\Console\Output\OutputInterface;
17+
useSymfony\Component\Console\Style\SymfonyStyle;
18+
19+
/**
20+
* Show the deprecations generated during the cache warmup.
21+
*
22+
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
23+
*
24+
* @final
25+
*/
26+
class DebugDeprecationsWarmedCommandextends Command
27+
{
28+
protectedstatic$defaultName ='debug:deprecations:warmed';
29+
30+
private$containerDeprecationFilePath;
31+
32+
publicfunction__construct(string$containerDeprecationFilePath)
33+
{
34+
parent::__construct();
35+
36+
$this->containerDeprecationFilePath =$containerDeprecationFilePath;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protectedfunctionconfigure()
43+
{
44+
$this
45+
->setDescription('Show the deprecated calls generated during cache:warmup')
46+
->setHelp(<<<'EOF'
47+
The <info>%command.name%</info> shows depecrated calls generated during cache:warmup
48+
49+
<info>php %command.full_name%</info>
50+
EOF
51+
)
52+
;
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
protectedfunctionexecute(InputInterface$input,OutputInterface$output)
59+
{
60+
$io =newSymfonyStyle($input,$output);
61+
if (!file_exists($this->containerDeprecationFilePath)) {
62+
$io->warning('The deprecation file does not exist, please try warming the cache before.');
63+
64+
return;
65+
}
66+
67+
$logs =unserialize(file_get_contents($this->containerDeprecationFilePath));
68+
if (0 ===\count($logs)) {
69+
$io->success('There are no deprecations in the logs!');
70+
71+
return;
72+
}
73+
74+
$formattedLogs = [];
75+
$remainingCount =0;
76+
foreach ($logsas$log) {
77+
$formattedLogs[] =sprintf("%sx: %s\n in %s:%s",$log['count'],$log['message'],$log['file'],$log['line']);
78+
$remainingCount +=$log['count'];
79+
}
80+
$io->title(sprintf('Remaining warmup deprecations (%s)',$remainingCount));
81+
$io->listing($formattedLogs);
82+
}
83+
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
<tagname="console.command"command="debug:event-dispatcher" />
8282
</service>
8383

84+
<serviceid="console.command.debug_deprecation_warmed"class="Symfony\Bundle\FrameworkBundle\Command\DebugDeprecationsWarmedCommand">
85+
<argument>%kernel.cache_dir%/%kernel.container_class%Deprecations.log</argument>
86+
<tagname="console.command"command="debug:deprecations:warmed" />
87+
</service>
88+
8489
<serviceid="console.command.messenger_consume_messages"class="Symfony\Component\Messenger\Command\ConsumeMessagesCommand">
8590
<argumenttype="service"id="messenger.routable_message_bus" />
8691
<argumenttype="service"id="messenger.receiver_locator" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
useSymfony\Bundle\FrameworkBundle\Command\DebugDeprecationsWarmedCommand;
15+
useSymfony\Bundle\FrameworkBundle\Tests\TestCase;
16+
useSymfony\Component\Console\Application;
17+
useSymfony\Component\Console\Tester\CommandTester;
18+
19+
class DebugDeprecationsWarmedCommandTestextends TestCase
20+
{
21+
publicfunctiontestGetDeprecation()
22+
{
23+
$path =tempnam(sys_get_temp_dir(),'sf');
24+
touch($path);
25+
file_put_contents($path,'a:2:{i:0;a:6:{s:4:"type";i:16384;s:7:"message";s:171:"The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.";s:4:"file";s:87:"/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php";s:4:"line";i:17;s:5:"trace";a:1:{i:0;a:3:{s:4:"file";s:66:"/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php";s:4:"line";i:9;s:8:"function";s:17:"spl_autoload_call";}}s:5:"count";i:1;}i:1;a:6:{s:4:"type";i:16384;s:7:"message";s:188:"The "App\Controller\DefaultController" class extends "Symfony\Bundle\FrameworkBundle\Controller\Controller" that is deprecated since Symfony 4.2, use {@see AbstractController} instead.
26+
*.";s:4:"file";s:71:"/home/hamza/projet/contrib/sf/vendor/symfony/debug/DebugClassLoader.php";s:4:"line";i:191;s:5:"trace";a:1:{i:0;a:1:{s:8:"function";s:17:"spl_autoload_call";}}s:5:"count";i:1;}}');
27+
28+
/** @var CommandTester $tester */
29+
$tester =$this->getCommandTester($path);
30+
$tester->execute([]);
31+
32+
$this->assertSame(0,$tester->getStatusCode());
33+
$this->assertContains('Symfony\Bundle\FrameworkBundle\Controller\Controller',$tester->getDisplay());
34+
$this->assertContains('/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php',$tester->getDisplay());
35+
}
36+
37+
publicfunctiontestGetDeprecationNone()
38+
{
39+
$path =tempnam(sys_get_temp_dir(),'sf');
40+
touch($path);
41+
file_put_contents($path,'a:0:{}');
42+
43+
/** @var CommandTester $tester */
44+
$tester =$this->getCommandTester($path);
45+
$tester->execute([]);
46+
47+
$this->assertSame(0,$tester->getStatusCode());
48+
$this->assertContains('[OK] There are no deprecations in the logs!',$tester->getDisplay());
49+
}
50+
51+
publicfunctiontestGetDeprecationNoFile():void
52+
{
53+
$tester =$this->getCommandTester('notexist');
54+
$tester->execute([]);
55+
56+
$this->assertSame(0,$tester->getStatusCode());
57+
$this->assertContains('[WARNING] The deprecation file does not exist',$tester->getDisplay());
58+
}
59+
60+
privatefunctiongetCommandTester($path):CommandTester
61+
{
62+
$command =newDebugDeprecationsWarmedCommand($path);
63+
$application =newApplication();
64+
$application->add($command);
65+
66+
returnnewCommandTester($application->get('debug:deprecations:warmed'));
67+
}
68+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp