Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,16 +1015,25 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
->ifArray()
->then(function ($v) {
$map = [];
$verbosities = ['VERBOSITY_QUIET', 'VERBOSITY_NORMAL', 'VERBOSITY_VERBOSE', 'VERBOSITY_VERY_VERBOSE', 'VERBOSITY_DEBUG'];
$verbosityConstants = [OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_VERBOSE, OutputInterface::VERBOSITY_VERY_VERBOSE, OutputInterface::VERBOSITY_DEBUG];
// allow numeric indexed array with ascending verbosity and lowercase names of the constants
$verbosities = [
// allow numeric indexed array with ascending verbosity
0 => 'VERBOSITY_QUIET',
1 => 'VERBOSITY_NORMAL',
2 => 'VERBOSITY_VERBOSE',
3 => 'VERBOSITY_VERY_VERBOSE',
4 => 'VERBOSITY_DEBUG',
// or array indexed by verbosity constants
OutputInterface::VERBOSITY_QUIET => 'VERBOSITY_QUIET',
OutputInterface::VERBOSITY_NORMAL => 'VERBOSITY_NORMAL',
OutputInterface::VERBOSITY_VERBOSE => 'VERBOSITY_VERBOSE',
OutputInterface::VERBOSITY_VERY_VERBOSE => 'VERBOSITY_VERY_VERBOSE',
OutputInterface::VERBOSITY_DEBUG => 'VERBOSITY_DEBUG',
];
foreach ($v as $verbosity => $level) {
if (is_int($verbosity) && isset($verbosities[$verbosity])) {
$map[$verbosities[$verbosity]] = strtoupper($level);
} elseif (is_int($verbosity) && false !== $i = \array_search($verbosity, $verbosityConstants, true)) {
$map[$verbosities[$i]] = strtoupper($level);
$map[$verbosities[$verbosity]] = $level;
} else {
$map[strtoupper($verbosity)] = strtoupper($level);
$map[strtoupper($verbosity)] = $level;
}
}

Expand Down
20 changes: 19 additions & 1 deletion Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,28 @@ public function provideConsoleHandlerCases(): iterable
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG
]
];

yield 'with numeric index' => [
[
LOGGER::ALERT,
LOGGER::ERROR,
LOGGER::WARNING,
LOGGER::NOTICE,
LOGGER::INFO,
],
[
OutputInterface::VERBOSITY_QUIET => Logger::ALERT,
OutputInterface::VERBOSITY_NORMAL => Logger::ERROR,
OutputInterface::VERBOSITY_VERBOSE => Logger::WARNING,
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::NOTICE,
OutputInterface::VERBOSITY_DEBUG => Logger::INFO,
]
];

yield 'with constants' => [
[
OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE,
'verbosity_verbose' => 'info',
OutputInterface::VERBOSITY_VERBOSE => 'info',
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO
],
[
Expand Down