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

(How) can i combine FormatValidation and CHECK_MODE_COERCE_TYPES #445

Closed
victor-lund opened this issue Sep 19, 2017 · 3 comments
Closed

Comments

@victor-lund
Copy link

I'm a bit confused about how to combine different validation techniques. As i understand it, I can use CHECK_MODE_COERCE_TYPES to check types objects, arrays, integers, strings etc. as well as parameter requirements maxLength, minLength (strings), maximium, minimum (integers) etc.

However, if I also want to check if a parameter is an email string, I need to use FormatValidation (CHECK_MODE_COERCE_TYPES apparently only checks if the email parameter is a string).

So - I suppose I need to combine FormatValidation and CHECK_MODE_COERCE_TYPES. I'm not sure how to do that properly.

        $validator = new \JsonSchema\Validator();

        $validator->validate(
            $postedArray,
            $schema,
            Constraint::CHECK_MODE_COERCE_TYPES);

        $validator->validate(
            $postedArray,
            $schema,
            Constraint::CHECK_MODE_FormatConstraint);

I'm looking for something like this, but I assume this is not the proper way to go about it..?

@erayd
Copy link
Contributor

erayd commented Sep 19, 2017

They are just integers, and can be manipulated using standard bitwise operations. To enable multiple flags at the same time, use bitwise OR (|).

@erayd
Copy link
Contributor

erayd commented Sep 19, 2017

Also, please read the readme. Those flags do not mean what you think they mean! Types are always checked, regardless of whether or not CHECK_MODE_COERCE_TYPES is enabled. And CHECK_MODE_FormatConstraint isn't a flag at all.

You do not need to manually enable the format keyword; if the keyword is present in the schema, then it will be checked.

@DannyvdSluijs
Copy link
Collaborator

@victor-lund in an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume this is a rather old issue, which seems answered and can be closed? Feel free to close it yourself with some comments if helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants