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

Custom coercion to types. #524

Closed
adjenks opened this issue Jul 19, 2018 · 2 comments
Closed

Custom coercion to types. #524

adjenks opened this issue Jul 19, 2018 · 2 comments

Comments

@adjenks
Copy link

adjenks commented Jul 19, 2018

I believe you should be able to enable more elaborate coercion of data types.
For example, coercing 'on' to true, or 'off' to false.
This could be implemented via a custom callback.
Just swap out functions like TypeConstrain->toBoolean() with optional custom callbacks.
For example:

$v = new \JsonSchema\Validator();
$v->setBooleanCoercion(function ($value)
    {
        if ($value === 'true' || $value === 'on') {
            return true;
        }

        if ($value === 'false' || $value === 'off') {
            return false;
        }

        return $value;
    }
});
@adjenks adjenks changed the title Add more coercion to boolean. Custom coercion to types. Jul 19, 2018
@shmax
Copy link
Collaborator

shmax commented Jul 20, 2018

PRs welcome.

@DannyvdSluijs
Copy link
Collaborator

@adjenks 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, and no effort was made to create a PR? 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