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 61eb2e1

Browse filesBrowse files
committed
CacheWarmerAggregate handle deprecations logs
1 parent 3bade96 commit 61eb2e1
Copy full SHA for 61eb2e1

File tree

2 files changed

+51
-1
lines changed
Filter options

2 files changed

+51
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true">
3434
<argument type="tagged" tag="kernel.cache_warmer" />
35+
<argument>%kernel.debug%</argument>
36+
<argument>%kernel.cache_dir%/%kernel.container_class%</argument>
3537
</service>
3638

3739
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer" public="true">

‎src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php
+49-1Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
class CacheWarmerAggregate implements CacheWarmerInterface
2222
{
2323
private $warmers;
24+
private $debug;
25+
private $containerPathPrefix;
2426
private $optionalsEnabled = false;
2527
private $onlyOptionalsEnabled = false;
2628

27-
public function __construct(iterable $warmers = array())
29+
public function __construct(iterable $warmers = array(), bool $debug = false, string $containerPathPrefix = null)
2830
{
2931
$this->warmers = $warmers;
32+
$this->debug = $debug;
33+
$this->containerPathPrefix = $containerPathPrefix;
3034
}
3135

3236
public function enableOptionalWarmers()
@@ -46,6 +50,40 @@ public function enableOnlyOptionalWarmers()
4650
*/
4751
public function warmUp($cacheDir)
4852
{
53+
if ($this->debug) {
54+
$collectedLogs = array();
55+
$previousHandler = defined('PHPUNIT_COMPOSER_INSTALL');
56+
$previousHandler = $previousHandler ?: set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) {
57+
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
58+
return $previousHandler ? $previousHandler($type, $message, $file, $line) : false;
59+
}
60+
61+
if (isset($collectedLogs[$message])) {
62+
++$collectedLogs[$message]['count'];
63+
64+
return;
65+
}
66+
67+
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
68+
// Clean the trace by removing first frames added by the error handler itself.
69+
for ($i = 0; isset($backtrace[$i]); ++$i) {
70+
if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
71+
$backtrace = array_slice($backtrace, 1 + $i);
72+
break;
73+
}
74+
}
75+
76+
$collectedLogs[$message] = array(
77+
'type' => $type,
78+
'message' => $message,
79+
'file' => $file,
80+
'line' => $line,
81+
'trace' => $backtrace,
82+
'count' => 1,
83+
);
84+
});
85+
}
86+
4987
foreach ($this->warmers as $warmer) {
5088
if (!$this->optionalsEnabled && $warmer->isOptional()) {
5189
continue;
@@ -56,6 +94,16 @@ public function warmUp($cacheDir)
5694

5795
$warmer->warmUp($cacheDir);
5896
}
97+
98+
if ($this->debug && true !== $previousHandler) {
99+
if (null !== $this->containerPathPrefix && file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
100+
$previousLogs = unserialize(file_get_contents($file));
101+
$deprecatedLogs = array_merge($previousLogs, $collectedLogs);
102+
file_put_contents($this->containerPathPrefix.'Deprecations.log', serialize(array_values($deprecatedLogs)));
103+
}
104+
105+
restore_error_handler();
106+
}
59107
}
60108

61109
/**

0 commit comments

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