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

Error when trying to use cast and coerce #321

Closed
iongion opened this issue Oct 13, 2016 · 4 comments
Closed

Error when trying to use cast and coerce #321

iongion opened this issue Oct 13, 2016 · 4 comments

Comments

@iongion
Copy link

iongion commented Oct 13, 2016

Using json-schema 4.0, for this code that respects documentation on github repo home page:

            $validator = new Validator(
                Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE
            );

The error is:

Uncaught TypeError: Argument 1 passed to JsonSchema\Constraints\Constraint::__construct() must be an instance of JsonSchema\Constraints\Factory, integer given .... defined in vendor\justinrainbow\json-schema\src\JsonSchema\Constraints\Constraint.php:40

I've noticed now it expects a factory, how can it be solved as I have no clue on how to pass the factory

@gtuccini
Copy link

gtuccini commented Oct 16, 2016

I had the same problem. I solved it by using:

use \JsonSchema\Constraints\Constraint;
use \JsonSchema\Constraints\Factory;
use \JsonSchema\Validator;
$validator = new Validator(new Factory(
    null, 
    null, 
    Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE
));

@steffkes
Copy link
Contributor

@iongion where in the docs did you find this example? i remember a PR around Factory being merge some time ago - probably we forgot to update the docs for this topic

@shmax
Copy link
Collaborator

shmax commented Oct 26, 2016

This PR syncs the readme with the code, but it also changes the API a bit:
#320

Comments welcome.

@iongion
Copy link
Author

iongion commented Oct 27, 2016

@steffkes I mentioned it is on the github home repo page, that is where I took it from, now I see the factory, which is good! 👍

@iongion iongion closed this as completed Oct 27, 2016
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

4 participants