-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Fix behavior for controller actions with union types #20352
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
base: master
Are you sure you want to change the base?
Conversation
! fix yii\web\Controller::bindActionParams behaviour for union types o some refactoring in the process
o cleanup, changelog
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #20352 +/- ##
============================================
- Coverage 63.44% 63.38% -0.06%
- Complexity 11445 11468 +23
============================================
Files 431 431
Lines 37207 37251 +44
============================================
+ Hits 23606 23612 +6
- Misses 13601 13639 +38 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Does |
if ($type instanceof \ReflectionNamedType) { | ||
[$result, $isValid] = $this->filterSingleTypeActionParam($params[$name], $type); | ||
$params[$name] = $result; | ||
} elseif (class_exists('\ReflectionUnionType') && $type instanceof \ReflectionUnionType) { |
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.
I don't think class_exists
is needed here.
Would you please measure performance impact w/ phpbench if possible? |
This fixes the behaviour for
yii\web\Controller::bindActionParams
when a function parameter has a union type.In effect, this fixes two issues:
string|int
), if the parameter value is a string containing a numeric value (such as'1'
), the result will be the numeric value ((int)1
here) rather than the string.int|array
), if the parameter value is an array, the controller no longer throws aBadRequestHttpException
, fixing "Bad request" for array parameter with union type #20351.