Skip to content
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

Validators: support for types int[] and string[] #119

Closed
JanTvrdik opened this issue Aug 2, 2016 · 9 comments
Closed

Validators: support for types int[] and string[] #119

JanTvrdik opened this issue Aug 2, 2016 · 9 comments

Comments

@JanTvrdik
Copy link
Contributor

@JanTvrdik JanTvrdik commented Aug 2, 2016

How do you feel about supporting either specifically int[] and string[] (defined as list where all values are of given type)?

Or we can generally support anything[], but I don't think that's necessary.

@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

@JanTvrdik JanTvrdik commented Aug 2, 2016

Alternative approach: add Validators::isListOfType($value, $type) or add new optional parameter $type to current isList method. But then you cannot simple use Validators::assert(). You can however use PHP built-in assert().

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 22, 2016

Do you have any use real cases for this?

@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

@JanTvrdik JanTvrdik commented Sep 22, 2016

Yes, of couse. For example list of ids in query param.

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 22, 2016

Could you prepare PR for this?

@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

@JanTvrdik JanTvrdik commented Sep 22, 2016

It's undecided how this should be implemented (see the first two comments). The implementation itself is likely trivial.

@TomasVotruba

This comment has been minimized.

Copy link

@TomasVotruba TomasVotruba commented Sep 22, 2016

Validators::isListOfType($value, $type) seems much clear to me and describes the intention better.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Sep 26, 2016

And what if it is not a list, but a map (i.e. key => value array)?

@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

@JanTvrdik JanTvrdik commented Sep 26, 2016

@dg Then it will return FALSE =)

Would you prefer more general approach, e.g. array<string, bool> or vector<string>?

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Sep 26, 2016

In PHP is more understandable anything[] than array<anything>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.