Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using OutputInterface::VERBOSITY_* constants in PHP config #439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HeahDude
Copy link

@HeahDude HeahDude commented May 21, 2022

While trying to improve some configuration blocks in Symfony docs, I found out that it was not possible to use constants for the verbosity levels of the console handler.
I think it's missing now that we tend to spread PHP config files such as config/packages/monolog.php.

Before this patch one gets the following exception:

Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized options "32, 128" under "monolog.handlers.console.verbosity_levels". Available options are "VERBOSITY_DEBUG", "VERBOSITY_NORMAL", "VERBOSITY_QUIET", "VERBOSITY_VERBOSE", "VERBOSITY_VERY_VERBOSE".

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 for allowing constant instead of "magic" strings.

There is a 2nd transformation of constant name to constant value in the config validation callback. All that may be simplified by converting to const values in the normalization.

The only drawback is that there will be int displayed instead of constant names when using debug:config.

@@ -1015,10 +1016,13 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
->then(function ($v) {
$map = [];
$verbosities = ['VERBOSITY_QUIET', 'VERBOSITY_NORMAL', 'VERBOSITY_VERBOSE', 'VERBOSITY_VERY_VERBOSE', 'VERBOSITY_DEBUG'];
// allow numeric indexed array with ascendning verbosity and lowercase names of the constants
$verbosityConstants = [OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_VERBOSE, OutputInterface::VERBOSITY_VERY_VERBOSE, OutputInterface::VERBOSITY_DEBUG];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array should look like [OutputInterface::VERBOSITY_QUIET => 'VERBOSITY_QUIET', ...] to remove the array_search and make the code more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the code a little clearer with this changes: HeahDude#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants