Skip to content

Commit fae3ad7

Browse files
committed
feature #384 Typo in console formatter option name (HypeMC)
This PR was squashed before being merged into the 3.x-dev branch. Discussion ---------- Typo in console formatter option name The `console_formater_options` has a typo. This PR deprecates the option and replaces it with `console_formatter_options` while maintaining backwards compatibility. Commits ------- 979580a Typo in console formatter option name
2 parents 165e7a3 + 979580a commit fae3ad7

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* - [verbosity_levels]: level => verbosity configuration
3939
* - [level]: level name or int value, defaults to DEBUG
4040
* - [bubble]: bool, defaults to true
41-
* - [console_formater_options]: array
41+
* - [console_formatter_options]: array
4242
*
4343
* - firephp:
4444
* - [level]: level name or int value, defaults to DEBUG
@@ -658,12 +658,19 @@ public function getConfigTreeBuilder()
658658
->end()
659659
// console
660660
->variableNode('console_formater_options')
661-
->defaultValue([])
661+
->setDeprecated('"%path%.%node%" is deprecated, use "%path%.console_formatter_options" instead.')
662662
->validate()
663663
->ifTrue(function ($v) {
664664
return !is_array($v);
665665
})
666-
->thenInvalid('console_formater_options must an array.')
666+
->thenInvalid('The console_formater_options must be an array.')
667+
->end()
668+
->end()
669+
->variableNode('console_formatter_options')
670+
->defaultValue([])
671+
->validate()
672+
->ifTrue(static function ($v) { return !is_array($v); })
673+
->thenInvalid('The console_formatter_options must be an array.')
667674
->end()
668675
->end()
669676
->arrayNode('verbosity_levels') // console
@@ -784,6 +791,18 @@ public function getConfigTreeBuilder()
784791
->scalarNode('formatter')->end()
785792
->booleanNode('nested')->defaultFalse()->end()
786793
->end()
794+
->beforeNormalization()
795+
->always(static function ($v) {
796+
if (empty($v['console_formatter_options']) && !empty($v['console_formater_options'])) {
797+
$v['console_formatter_options'] = $v['console_formater_options'];
798+
}
799+
800+
return $v;
801+
})
802+
->end()
803+
->validate()
804+
->always(static function ($v) { unset($v['console_formater_options']); return $v; })
805+
->end()
787806
->validate()
788807
->ifTrue(function ($v) { return 'service' === $v['type'] && !empty($v['formatter']); })
789808
->thenInvalid('Service handlers can not have a formatter configured in the bundle, you must reconfigure the service itself instead')

DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
220220
null,
221221
$handler['bubble'],
222222
isset($handler['verbosity_levels']) ? $handler['verbosity_levels'] : [],
223-
$handler['console_formater_options']
223+
$handler['console_formatter_options']
224224
]);
225225
$definition->addTag('kernel.event_subscriber');
226226
break;

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ public function testWithNestedHandler()
361361

362362
$this->assertTrue($config['handlers']['foobar']['nested']);
363363
}
364+
364365
public function testWithRedisHandler()
365366
{
366367
$configs = [
@@ -406,6 +407,88 @@ public function testWithRedisHandler()
406407
$this->assertEquals('monolog_redis_test', $config['handlers']['redis']['redis']['key_name']);
407408
}
408409

410+
/**
411+
* @group legacy
412+
*/
413+
public function testConsoleFormatterOptionsRename()
414+
{
415+
$configs = [
416+
[
417+
'handlers' => [
418+
'old' => [
419+
'type' => 'console',
420+
'console_formater_options' => ['foo' => 'foo'],
421+
],
422+
'old2' => [
423+
'type' => 'console',
424+
'console_formater_options' => ['foo' => 'foo'],
425+
],
426+
'new' => [
427+
'type' => 'console',
428+
'console_formatter_options' => ['bar' => 'bar'],
429+
],
430+
'new2' => [
431+
'type' => 'console',
432+
'console_formatter_options' => ['bar' => 'bar'],
433+
],
434+
'both' => [
435+
'type' => 'console',
436+
'console_formater_options' => ['foo' => 'foo'],
437+
'console_formatter_options' => ['bar' => 'bar'],
438+
],
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+
],
461+
],
462+
],
463+
];
464+
465+
$config = $this->process($configs);
466+
467+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['old']);
468+
$this->assertSame(['foo' => 'foo'], $config['handlers']['old']['console_formatter_options']);
469+
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['old']);
470+
471+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['new']);
472+
$this->assertSame(['bar' => 'bar'], $config['handlers']['new']['console_formatter_options']);
473+
$this->assertArrayNotHasKey('console_formater_options', $config['handlers']['new']);
474+
475+
$this->assertArrayHasKey('console_formatter_options', $config['handlers']['both']);
476+
$this->assertSame(['bar' => 'bar'], $config['handlers']['both']['console_formatter_options']);
477+
$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']);
490+
}
491+
409492
/**
410493
* Processes an array of configurations and returns a compiled version.
411494
*

0 commit comments

Comments
 (0)