Skip to content

Commit e879945

Browse files
committed
bug #22961 [HttpKernel] Support unknown format in LoggerDataCollector (iltar)
This PR was merged into the 3.3 branch. Discussion ---------- [HttpKernel] Support unknown format in LoggerDataCollector | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22952 | License | MIT | Doc PR | ~ The new expected format for the compiler log is `CompilerPassClass: Message`. However, this is not enforced by the old logging method as seen in schmittjoh/JMSDiExtraBundle#276 This PR adds the ability to read those lines without crashing with `Uncaught Notice: Undefined offset: 1`. Please note that I have not tested this in an application so testers are welcome to confirm this fix! Commits ------- a8dfbb1 Support unknown compiler log format
2 parents 44f3482 + a8dfbb1 commit e879945

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ private function getContainerCompilerLogs()
138138
$logs = array();
139139
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
140140
$log = explode(': ', $log, 2);
141+
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
142+
$log = array('Unknown Compiler Pass', implode(': ', $log));
143+
}
141144

142145
$logs[$log[0]][] = array('message' => $log[1]);
143146
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Psr\Container\ContainerInterface"; reason: private alias.
2+
Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass: Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.
3+
Some custom logging message
4+
With ending :

src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717

1818
class LoggerDataCollectorTest extends TestCase
1919
{
20+
public function testCollectWithUnexpectedFormat()
21+
{
22+
$logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
23+
$logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo'));
24+
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue(array()));
25+
26+
$c = new LoggerDataCollector($logger, __DIR__.'/');
27+
$c->lateCollect();
28+
$compilerLogs = $c->getCompilerLogs()->getValue('message');
29+
30+
$this->assertSame(array(
31+
array('message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'),
32+
array('message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'),
33+
), $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
34+
35+
$this->assertSame(array(
36+
array('message' => 'Some custom logging message'),
37+
array('message' => 'With ending :'),
38+
), $compilerLogs['Unknown Compiler Pass']);
39+
}
40+
2041
/**
2142
* @dataProvider getCollectTestData
2243
*/

0 commit comments

Comments
 (0)