Skip to content

[OptionsResolver] Support array of types in allowed type #23112

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

Merged
merged 1 commit into from
Oct 12, 2017

Conversation

pierredup
Copy link
Contributor

@pierredup pierredup commented Jun 8, 2017

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

@pierredup pierredup changed the title Support array of types in allowed type [OptionsResolver] Support array of types in allowed type Jun 8, 2017
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jun 8, 2017
3.4.0
-----

* added array of types support in allowed types
Copy link
Contributor

@robfrawley robfrawley Jun 9, 2017

Choose a reason for hiding this comment

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

Would it not make it more clear to add a short example here? For example:

added array of types support in allowed types (e.g. int[])

@linaori
Copy link
Contributor

linaori commented Jun 9, 2017

What if I have an array of custom items?

$resolver->setAllowedType('foo', Foo::class.'[]');
// or
$resolver->setAllowedType('foo', '\App\Bar\Foo[]');

This seems a bit annoying to write.

@pierredup
Copy link
Contributor Author

The syntax follows the standard phpdoc notation, which IMO is clear what it means. Even though it can be a bit annoying to write, just looking at the code still reads easily and is clear what it means

@xabbuh
Copy link
Member

xabbuh commented Jun 10, 2017

This misses the case where the passed value isn't an array, doesn't it?

@pierredup
Copy link
Contributor Author

If the passed value isn't an array, then you'll get an exception saying, e.g, ... is expected to be of type "int[]", but is of type string

@xabbuh
Copy link
Member

xabbuh commented Jun 10, 2017

Might be a good idea to add a test case for that too.

@robfrawley
Copy link
Contributor

I'd greatly prefer this supported the whole test suite introduces in #17032, instead of a subset of those features. For example, nested values.

@pierredup
Copy link
Contributor Author

The syntax for the nested values just feels a bit weird to me. Looking at it initially took a moment or two to understand exactly what it means. And the further you nest it, the weirder it becomes, E.G int[][][][]. We can maybe limit the nesting to 2 levels only, or maybe there is a different syntax that we can use like for example int[]+ to indicate multiple levels or int[5] to indicate for example 5 nested levels, or if we can just stick to appending [] indefinitely

@robfrawley
Copy link
Contributor

robfrawley commented Jun 23, 2017

@pierredup I prefer the original phpdoc syntax of int[][], but I'm also not again using a different syntax if you think it adds clarity. I'm not particularly hung-up on the syntax, as long as the functionality exists.

@stof
Copy link
Member

stof commented Jun 23, 2017

int[][][][] is the phpdoc syntax. So IMO, if we decide to support nesting, it should use this syntax rather than inventing our own syntax

@ro0NL
Copy link
Contributor

ro0NL commented Jul 20, 2017

What about borrowing some inspiration of react proptypes, instead?

Im thinking notNull(), oneOf(), oneOfType(), instanceOf() api =/

@pierredup pierredup force-pushed the options-array branch 2 times, most recently from 379de0d to 14a0707 Compare September 26, 2017 21:11
@pierredup
Copy link
Contributor Author

Support for nested values added (E.G int[][][]).

Status: needs review

}

if (!$invalidTypes) {
$invalidTypes[] = $this->formatTypeOf($value, null);
Copy link
Member

Choose a reason for hiding this comment

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

What about using the types as keys instead and then get rid of the array_unique() keys (replace it with array_keys())?

Copy link
Member

Choose a reason for hiding this comment

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

fixed

@fabpot
Copy link
Member

fabpot commented Oct 12, 2017

Thank you @pierredup.

@fabpot fabpot merged commit d066a23 into symfony:3.4 Oct 12, 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
This was referenced Oct 18, 2017
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.

10 participants