-
Notifications
You must be signed in to change notification settings - Fork 30
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
Inject possible dependencies in codec and validator #14
Conversation
e7ecc77
to
e329fce
Compare
Hi @bburnichon, thank you for this PR! :) What's the use case for this change? |
I have a silex project where I need to configure specific validation for each encoding/decoding. This way, library is fully decoupled and I can have a configured JsonDecoder/JsonEncoder in Pimple container for each use case. Also, I already have a $app['json-schema.retriever'] = $app->share(function () {
return new UriRetriever();
});
$app['json-schema.validator_factory'] = $app->protect(function () use ($app) {
return new Validator($app['json-schema.url_retriever']);
});
$app['json.validator'] = $app->share(function (Application $app) {
return new JsonValidator($app['json-schema.validator_factory']);
});
$app['json.decoder'] = $app->share(function (Application $app) {
return new JsonDecoder($app['json.validator']);
}); |
/** | ||
* JsonValidator constructor. | ||
* | ||
* @param callable|null $validatorFactory Factory creating JsonSchema\Validator instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need support for callables in here instead of directly injecting the Validator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because a new instance of Validator should be used at each call to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you simply reset()
the validator before using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(which, of course, I could have done too :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I did not knew it exists! ;)
This PR includes all changes from #9. @webmozart I can squash commits if you prefer to keep a clean history. |
/** | ||
* @return Validator | ||
*/ | ||
private function prepareValidator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating! :) I don't think this needs to live in a separate method. You can simply inline the reset()
call above.
85bb1cf
to
1ad5453
Compare
No, looks good :) Thanks a lot @bburnichon! |
Inject possible dependencies in codec and validator
Make it possible to configure options on validators used