Skip to content

Commit 0bb4104

Browse files
committed
minor #396 Fix deprecation (jderusse)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix deprecation Commits ------- 5c49a79 Fix deprecation
2 parents fae3ad7 + 5c49a79 commit 0bb4104

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MonologBundle\DependencyInjection;
1313

14+
use Symfony\Component\Config\Definition\BaseNode;
1415
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1516
use Symfony\Component\Config\Definition\ConfigurationInterface;
1617
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@@ -658,7 +659,7 @@ public function getConfigTreeBuilder()
658659
->end()
659660
// console
660661
->variableNode('console_formater_options')
661-
->setDeprecated('"%path%.%node%" is deprecated, use "%path%.console_formatter_options" instead.')
662+
->setDeprecated(...$this->getDeprecationMsg('"%path%.%node%" is deprecated, use "%path%.console_formatter_options" instead.', 3.7))
662663
->validate()
663664
->ifTrue(function ($v) {
664665
return !is_array($v);
@@ -996,4 +997,27 @@ public function getConfigTreeBuilder()
996997

997998
return $treeBuilder;
998999
}
1000+
1001+
/**
1002+
* Returns the correct deprecation param's as an array for setDeprecated.
1003+
*
1004+
* Symfony/Config v5.1 introduces a deprecation notice when calling
1005+
* setDeprecation() with less than 3 args and the getDeprecation method was
1006+
* introduced at the same time. By checking if getDeprecation() exists,
1007+
* we can determine the correct param count to use when calling setDeprecated.
1008+
*
1009+
* @return array{0:string}|array{0:string, 1: numeric-string, string}
1010+
*/
1011+
private function getDeprecationMsg(string $message, string $version): array
1012+
{
1013+
if (method_exists(BaseNode::class, 'getDeprecation')) {
1014+
return [
1015+
'symfony/monolog-bundle',
1016+
$version,
1017+
$message,
1018+
];
1019+
}
1020+
1021+
return [$message];
1022+
}
9991023
}

0 commit comments

Comments
 (0)