Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #35400 [RFC][DX][OptionsResolver] Allow setting info message …
…per option (yceruto) This PR was merged into the 5.1-dev branch. Discussion ---------- [RFC][DX][OptionsResolver] Allow setting info message per option | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | TODO This is a DX proposal that will help in debugging/errors to better understand the meaning of one defined option. This is how you'd use it: ```php $resolver = new OptionsResolver(); $resolver->setDefined('date'); $resolver->setAllowedTypes('date', \DateTime::class); $resolver->setInfo('date', 'A future date'); // <-- NEW // ... ``` This information may be useful for those options where their name cannot be intuitive enough, or their purpose is too complex. Here is an example (based on the example above): ```php // ... $resolver->setAllowedValues('date', static function ($value): bool { return $value >= new \DateTime('now'); }); ``` So, if you introduce a date value that does not match the criteria, you will get this error message: **Before:** ``` The option "date" with value DateTime is invalid. ``` Note that the allowed value is not printable in this case, hence the error message cannot be clear at all. **After:** ``` The option "date" with value DateTime is invalid. Info: A future date. ``` Although a more accurate error message can be triggered within the `\Closure` if desired. Also you'll see this info message on `debug:form` command (see tests), then you have in advance the informative description of any option. What do you think? Commits ------- 0477a06 Allow setting one info message per option
- Loading branch information
Showing
13 changed files
with
146 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters