-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[OptionsResolver] support array of instance validation #17032
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
Conversation
PR was reviewed in previous PR, so setting status to reviewed now |
* @param string $type the required allowedType string | ||
* @param mixed $value the value | ||
* | ||
* @return bool Whether or not $value if of the allowed type |
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.
is
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'd say "Whether the $value is of the allowed type".
there is a bunch of unrelated changes in this PR, making me think you messed the history a bit. |
Status: needs work (git history rebasing+squashing) |
@EVODelavega Are you also planning for a documentation PR about that? |
@soullivaneuh Just looking at the comments. I'd be more than happy to create a documentation PR, after I've fixed the docblocks. @nicolas-grekas: Do I really have to rebase + squash everything? If so: squash everything into a single commit and rebase on master? |
3aa9e04
to
7b0594d
Compare
@soullivaneuh Created documentation PR |
CHANGELOG-3.0.md
Outdated
@@ -26,7 +26,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c | |||
* bug #16312 [HttpKernel] clearstatcache() so the Cache sees when a .lck file has been released (mpdude) | |||
* bug #16351 [WIP] [Form] [TwigBridge] Bootstrap horizontal theme missing tests (pieter2627) | |||
* feature #16715 [Form] Remove choices_as_values option on ChoiceType (nicolas-grekas) | |||
* feature #16692 [Form] Drop remaing CsrfProviderAdapter/Interface mentions (nicolas-grekas) | |||
* feature #16692 [Form] Drop remaining CsrfProviderAdapter/Interface mentions (nicolas-grekas) |
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.
This change should be done in a different PR.
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.
Created a PR for the typo. Should I revert this change, or simply wait for the other PR to get merged and rebase the changes here?
This PR was merged into the 3.1-dev branch. Discussion ---------- Fix typo in changelog | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17084 | License | MIT | Doc PR | - Create separate PR as requested in [OptionsResolver PR](#17032) Commits ------- 6508b3d Fix typo in changelog
*/ | ||
private function verifyAllowedType($type, $value) | ||
{ | ||
if (mb_substr($type, -2) === '[]') { |
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.
all the calls to mb_substr should be replaced by plain substr calls imho
return $isFunction($value); | ||
} | ||
|
||
return ($value instanceof $type); |
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.
The parenthesis can be removed.
This looks like a good new feature. What do you think @symfony/deciders? |
@@ -1,6 +1,11 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
3.1.0 |
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.
Should be changed to 3.2.0 now.
In general I think the feature is not bad. I'm just not sure if it's worth since there is an easy solution already: #15524 (comment) Also, the allowed types now look like phpdoc vars but do not actually support all of the phpdoc features like |
I don't find the solution you mentioned that easy; and probably less than just having to add |
I am 👍 for supporting this. Looks quite reasonable and straight forward to me. |
Keep in mind the phpdoc interpretation of |
@Tobion I think this is not relevant for this PR as we are not implementing a phpdoc or PSR-5. We are just reusing something that people can understand easily as they are familiar with this notation. |
@EVODelavega Do you have time to take the comments into accounts? |
@fabpot It's been a while since I last looked at this PR, but I'm going to take all of the comments into account, work on it some more, and I'll let you know when it's ready. Thanks. |
@EVODelavega Are you still interested in finishing this PR? |
Just came searching for this feature. Any interest in finishing this off? Or someone taking over? |
I don't mind taking over if OP has no time. |
Or maybe someone else? |
@soullivaneuh see #23112 |
Ouch, is this still going? Erm, I suppose I can pick it up again should this be needed. It looks like the other PR implements this feature, though. I've switched from PHP to golang since opening this PR, so if there's an alternative PR that is more up-to-date, feel free to close this one. |
@EVODelavega would you be up rebasing this PR on 3.4 by the end of the week? Feature freeze is coming and there are some comments still pending also. |
…pe (pierredup) This PR was merged into the 3.4 branch. Discussion ---------- [OptionsResolver] Support array of types in allowed type | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17032, #15524 | License | MIT | Doc PR | TBD This replaces #17032 with a simpler approach to allow an array of types in the allowed types for the options resolver Note: This implementation doesn't support nested values (I.E `int[][]`), but if there is a strong need for it, I'll add it in another PR Commits ------- d066a23 Support array of types in allowed type
…VODelavega, wouterj) This PR was merged into the 3.4 branch. Discussion ---------- [OptionsResolver] Documented validation of array types This continues #6048 . The feature was finally merged into symfony 3.4 (congratz @EVODelavega!), so let's document it! Related Symfony PR: symfony/symfony#17032 Commits ------- cb12592 Merged new example in older example, removing some text 318e199 Fix typo bf5d9d3 Document typed arrays in optionsresolver
A suggested approach to add support for typed-arrays as allowed types, using a simple recursive method.
Closing PR 15671.