-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Improve ParameterNotFoundException when accessing a nested parameter #19584
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
[DependencyInjection] Improve ParameterNotFoundException when accessing a nested parameter #19584
Conversation
travis failure unrelated |
@@ -30,12 +31,13 @@ class ParameterNotFoundException extends InvalidArgumentException | |||
* @param \Exception $previous The previous exception | |||
* @param string[] $alternatives Some parameter name alternatives | |||
*/ | |||
public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array()) | |||
public function __construct($key, $sourceId = null, $sourceKey = null, \Exception $previous = null, array $alternatives = array(), $nonNestedAlternative = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$nonNestedAlternative
should be added to docblock, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
A common problem under beginners is to think that the dot notation is used to access nested arrays saved in parameters. Adding a little extra detail to the exception message and a working alternative should help pointing these people in the right direction before spending time debugging this.
1986299
to
f7a47d8
Compare
throw new ParameterNotFoundException($name, null, null, null, $alternatives); | ||
$nonNestedAlternative = null; | ||
if (!count($alternatives) && false !== strpos($name, '.')) { | ||
$namePartsLength = array_map('strlen', explode('.', $name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using implode ?
Thank you @wouterj. |
A common problem under beginners is to think that the dot notation is used to access nested arrays saved in parameters (common here means someone asks help for this problem at least once a week on IRC). Adding a little extra detail to the exception message and a working alternative should help pointing these people in the right direction before spending time debugging this.
It's quite late in the night over here, so the wording of the exception message probably isn't great. I'm happy to accept better suggestions 😃