Skip to content

Commit c8d9bf0

Browse files
committed
bug #556 Allow unset of excluded_http_codes (GromNaN)
This PR was merged into the 3.x branch. Discussion ---------- Allow unset of `excluded_http_codes` | Q | A | ------------- | --- | Branch? | 3.x | Bug fix? | yes | New feature? | yes/no | Deprecations? | yes/no | Issues | Fix #502 | License | MIT Removing the `excluded_http_codes` is allowed by `canBeUnset()` https://github.com/symfony/monolog-bundle/blob/ec54eb1624ae76056ddbeaa68e7db4bfe7ce774b/src/DependencyInjection/Configuration.php#L520-L521 There was an issue with the transformation of the array, as `array_map` is called with `false`. Commits ------- 7f4ae11 Allow unset of excluded_http_codes
2 parents ec54eb1 + 7f4ae11 commit c8d9bf0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,15 @@ public function getConfigTreeBuilder(): TreeBuilder
518518
->prototype('scalar')->end()
519519
->end()
520520
->arrayNode('excluded_http_codes') // fingers_crossed
521+
->info('Only for "fingers_crossed" handler type')
522+
->example([403, 404, [400 => ['^/foo', '^/bar']]])
521523
->canBeUnset()
522524
->beforeNormalization()
523525
->always(function ($values) {
526+
if (false === $values) {
527+
return false;
528+
}
529+
524530
return array_map(function ($value) {
525531
/*
526532
* Allows YAML:

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ public function testProcessStringChannels($string, $expectedString, $isInclusive
7474
$this->assertEquals($expectedString, $config['handlers']['foobar']['channels']['elements'][0]);
7575
}
7676

77+
public function testUnsetExcludedHttpCodes()
78+
{
79+
$configs = [
80+
[
81+
'handlers' => [
82+
'main' => [
83+
'type' => 'fingers_crossed',
84+
'action_level' => 'error',
85+
'handler' => 'nested',
86+
'excluded_http_codes' => [404, 405],
87+
'channels' => ['!event'],
88+
],
89+
'nested' => [
90+
'type' => 'stream',
91+
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
92+
'level' => 'debug',
93+
],
94+
],
95+
],
96+
[
97+
'handlers' => [
98+
'main' => [
99+
'type' => 'stream',
100+
'path' => '%kernel.logs_dir%/%kernel.environment%.log',
101+
'level' => 'debug',
102+
'excluded_http_codes' => false,
103+
],
104+
],
105+
],
106+
];
107+
108+
$config = $this->process($configs);
109+
110+
$this->assertArrayNotHasKey('excluded_http_codes', $config['handlers']['main']);
111+
$this->assertIsArray($config['handlers']['main']['channels']);
112+
}
113+
77114
public static function provideGelfPublisher(): array
78115
{
79116
return [

0 commit comments

Comments
 (0)