8000 Use before normalization instead of validate · symfony/monolog-bundle@7124611 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7124611

Browse files
committed
Use before normalization instead of validate
1 parent 9ea49ac commit 7124611

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

DependencyInjection/Configuration.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ public function getConfigTreeBuilder()
658658
// console
659659
->variableNode('console_formater_options')
660660
->setDeprecated('"%path%.%node%" is deprecated, use "%path%.console_formatter_options" instead.')
661-
->defaultValue([])
662661
->validate()
663662
->ifTrue(function ($v) {
664663
return !is_array($v);
@@ -791,6 +790,18 @@ public function getConfigTreeBuilder()
791790
->scalarNode('formatter')->end()
792791
->booleanNode('nested')->defaultFalse()->end()
793792
->end()
793+
->beforeNormalization()
794+
->always(static function ($v) {
795+
if (empty($v['console_formatter_options']) && !empty($v['console_formater_options'])) {
796+
$v['console_formatter_options'] = $v['console_formater_options'];
797+
}
798+
799+
return $v;
800+
})
801+
->end()
802+
->validate()
803+
->always(static function ($v) { unset($v['console_formater_options']); return $v; })
804+
->end()
794805
->validate()
795806
->ifTrue(function ($v) { return 'service' === $v['type'] && !empty($v['formatter']); })
796807
->thenInvalid('Service handlers can not have a formatter configured in the bundle, you must reconfigure the service itself instead')
@@ -954,17 +965,6 @@ public function getConfigTreeBuilder()
954965
->ifTrue(function ($v) { return 'predis' === $v['type'] && empty($v['redis']); })
955966
->thenInvalid('The host has to be specified to use a RedisLogHandler')
956967
->end()
957-
->validate()
958-
->always(static function ($v) {
959-
if (empty($v['console_formatter_options']) && !empty($v['console_formater_options'])) {
960-
$v['console_formatter_options'] = $v['console_formater_options'];
961-
}
962-
963-
unset($v['console_formater_options']);
964-
965-
return $v;
966-
})
967-
->end()
968968
->end()
969969
->validate()
970970
->ifTrue(function ($v) { return isset($v['debug']); })

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,45 @@ public function testConsoleFormatterOptionsRename()
419419
'type' => 'console',
420420
'console_formater_options' => ['foo' => 'foo'],
421421
],
422+
'old2' => [
423+
'type' => 'console',
424+
'console_formater_options' => ['foo' => 'foo'],
425+
],
422426
'new' => [
423427
'type' => 'console',
424428
'console_formatter_options' => ['bar' => 'bar'],
425429
],
430+
'new2' => [
431+
'type' => 'console',
432+
'console_formatter_options' => ['bar' => 'bar'],
433+
],
426434
'both' => [
427435
'type' => 'console',
428436
'console_formater_options' => ['foo' => 'foo'],
429437
'console_formatter_options' => ['bar' => 'bar'],
430438
],
439+
'both2' => [
440+
'type' => 'console',
441+
'console_formater_options' => ['foo' => 'foo'],
442+
'console_formatter_options' => ['bar' => 'bar'],
443+
],
444+
],
445+
],
446+
[
447+
'handlers' => [
448+
'old2' => [
449+
'type' => 'console',
450+
'console_formater_options' => ['baz' => 'baz'],
451+
],
452+
'new2' => [
453+
'type' => 'console',
454+
'console_formatter_options' => ['qux' => 'qux'],
455+
],
456+
'both2' => [
457+
'type' => 'console',
458+
'console_formater_options' => ['baz' => 'baz'],
459+
'console_formatter_options' => ['qux' => 'qux'],
460+
],
431461
],
432462
],
433463
];
@@ -445,6 +475,18 @@ public function testConsoleFormatterOptionsRename()
445475
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['both']);
446476
$this->assertSame(['bar' => 'bar'], $config['handlers']['both']['console_formatter_options']);
447477
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['both']);
478+
479+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['old2']);
480+
$this->assertSame(['baz' => 'baz'], $config['handlers']['old2']['console_formatter_options']);
481+
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['old2']);
482+
483+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['new2']);
484+
$this->assertSame(['qux' => 'qux'], $config['handlers']['new2']['console_formatter_options']);
485+
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['new2']);
486+
487+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['both2']);
488+
$this->assertSame(['qux' => 'qux'], $config['handlers']['both2']['console_formatter_options']);
489+
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['both2']);
448490
}
449491

450492
/**

0 commit comments

Comments
 (0)
0