-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add getAny
in InputBag
#36725
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
Add getAny
in InputBag
#36725
Conversation
Thank you for this PR. Could you elaborate a bit on the use case or the scenario where you need |
Sure
Example in my request: if ($this->isJson() && $content = $this->getContent()) {
$this->request->replace((array) json_decode($content, true));
} |
Thanks for the explanation, that helps a lot to get your pov.
I'm 👎 on my side with this reasoning. |
Thank you for the context. I like the implementation and the fact that you added a test. 👍 However, it is a good thing that you know the type of the return parameters. I also thing we should close this PR. |
Okay got it, thanks for your feedbacks ! And what do you think about introducing a |
You might be interested in having a look at #37100 (comment) |
The new
InputBag
was introduced in #34363 but there is an "edge case" to get a value of any type, I find it's better to be explicit and to have a new->getAny('foo', 'default')
instead of->all()['foo'] ?? 'default
(orarray_key_exists('foo', $...->all()) ? ...->all()['foo'] : 'default'
to be exact).Alternatively having a
->getString()
is more explicit than a generic->get()
.