thephpleague / json-guard

Validation of json-schema.org compliant schemas.
http://json-guard.thephpleague.com/
MIT License
175 stars 26 forks source link

Possibility fail if constraint is unknown #132

Open peterpostmann opened 6 years ago

peterpostmann commented 6 years ago

Hi Matt,

I want to continue the discussion from https://github.com/thephpleague/json-guard/pull/130: I have full understanding that you want to limit the scope of the library to what is supported by the specification.

My problem is, that there is right now no possibility to intercept the validation process. https://github.com/thephpleague/json-guard/blob/85c56116f8bae12ee961940b92bcd029e69e1fb4/src/Validator.php#L270-L272

I really need this feature and hence I kindly ask for your support. Aside from the requested change I see two other ways to make the validation interceptable. Maybe one of those is causing less maintenance, etc. effort.

1. Move the validation logic to the ruleset

Validator.php

    private function validateRule($keyword, $parameter)
    {
        return $this->ruleSet->validate($keyword)->validate($this->data, $parameter, $this);
    }

RuleSetContainer.php

    public function validate($keyword, $data, $parameter, $validator)
    {
        if (!$this->has($keyword)) {
            return null;
        }
        return $this->get($keyword)->validate($data, $parameter, $validator);
    }

2. Make Validator.php extendable

i.e. remove the final keyword and make validateRule protected instead of private.

Looking forward to your feedback!