Skip to content

[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

Closed
wants to merge 22 commits into from

Conversation

EVODelavega
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15524
License MIT
Doc PR symfony/symfony-docs#6048

A suggested approach to add support for typed-arrays as allowed types, using a simple recursive method.

Closing PR 15671.

@EVODelavega
Copy link
Contributor Author

PR was reviewed in previous PR, so setting status to reviewed now
Status: Reviewed

* @param string $type the required allowedType string
* @param mixed $value the value
*
* @return bool Whether or not $value if of the allowed type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is

Copy link
Contributor

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".

@stof
Copy link
Member

stof commented Dec 17, 2015

there is a bunch of unrelated changes in this PR, making me think you messed the history a bit.

@nicolas-grekas
Copy link
Member

Status: needs work (git history rebasing+squashing)

@soullivaneuh
Copy link
Contributor

@EVODelavega Are you also planning for a documentation PR about that?

@EVODelavega
Copy link
Contributor Author

@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?

@EVODelavega
Copy link
Contributor Author

@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)
Copy link
Member

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.

Copy link
Contributor Author

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?

fabpot added a commit that referenced this pull request Dec 21, 2015
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) === '[]') {
Copy link
Member

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);
Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Jun 16, 2016

This looks like a good new feature. What do you think @symfony/deciders?

@@ -1,6 +1,11 @@
CHANGELOG
=========

3.1.0
Copy link
Member

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.

@Tobion
Copy link
Contributor

Tobion commented Jun 16, 2016

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 int|float or (Foo|Bar)[] are not possible. So it's kinda arbitrary what it would support.

@fabpot
Copy link
Member

fabpot commented Jun 17, 2016

I don't find the solution you mentioned that easy; and probably less than just having to add []. I like the fact that we are reusing phpdoc notation here, and the fact that we do not support the whole notation yet does mean that this is arbitrary.

@xabbuh
Copy link
Member

xabbuh commented Jun 17, 2016

I am 👍 for supporting this. Looks quite reasonable and straight forward to me.

@Tobion
Copy link
Contributor

Tobion commented Jun 18, 2016

Keep in mind the phpdoc interpretation of int[] implemented here does only support arrays of integers, not traversables of integers. This seems consistent with the current working state of PSR-5. For collections one would need to specifiy \Traversable<int> which is not implemented here.

@fabpot
Copy link
Member

fabpot commented Jun 19, 2016

@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.

@fabpot
Copy link
Member

fabpot commented Jun 21, 2016

@EVODelavega Do you have time to take the comments into accounts?

@EVODelavega
Copy link
Contributor Author

@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.

@fabpot
Copy link
Member

fabpot commented Nov 9, 2016

@EVODelavega Are you still interested in finishing this PR?

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@bendavies
Copy link
Contributor

Just came searching for this feature. Any interest in finishing this off? Or someone taking over?

@bendavies
Copy link
Contributor

I don't mind taking over if OP has no time.

@soullivaneuh
Copy link
Contributor

@EVODelavega Are you still interested in finishing this PR?

Or maybe someone else?

@pierredup
Copy link
Contributor

@soullivaneuh see #23112

@EVODelavega
Copy link
Contributor Author

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.

@nicolas-grekas
Copy link
Member

@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.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
fabpot added a commit that referenced this pull request Oct 12, 2017
…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
@fabpot fabpot closed this Oct 12, 2017
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jan 2, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.