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

fix instancing wrong type, breaks inheritance #282

Merged
merged 1 commit into from
Jun 26, 2016

Conversation

bustbr
Copy link
Contributor

@bustbr bustbr commented Jun 22, 2016

when inheriting from TypeConstraint to change the behaviour of validateType (e.g. to add support for custom types), this would switch from the extended class to the base class if type is an array of types

e.g.

schema:

{
    "properties": {
        "foo": {
            "type": ["null", "Custom"]
        }
    }
}

doc:

{"foo": null}

Code:

class CustomTypeConstraint extends JsonSchema\Constraints\TypeConstraint {
    protected function validateType($value, $type) {
        if ('Custom' === $type) {
            return someFancyValueValidation($value); // doesn't matter..
        }
        return parent::validateType($value, $type);
    }
}

$factory = new JsonSchema\Constraints\Factory;
$factory->setConstraintClass('type', CustomTypeConstraint::class);
$validator = new JsonSchema\Validator(JsonSchema\Validator::CHECK_MODE_NORMAL, new JsonSchema\Uri\UriRetriever, $factory);
$validator->check($doc, $schema);

when inheriting from TypeConstraint to change the behaviour of `validateType` (e.g. to add support for custom types), this would switch from the extended class to the base class if type is an array of types
@bighappyface
Copy link
Collaborator

+1

@bighappyface bighappyface merged commit d414acd into jsonrainbow:master Jun 26, 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

Successfully merging this pull request may close these issues.

None yet

2 participants