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

Support custom cast function #52

Closed
JesusTheHun opened this issue Feb 8, 2023 · 1 comment
Closed

Support custom cast function #52

JesusTheHun opened this issue Feb 8, 2023 · 1 comment

Comments

@JesusTheHun
Copy link

It would like to be able to cast a value using a callable.

class Foo {
  public static function fromString($bar) {
    // some logic
  }
}

$schema = Expect::structure([
  'foo' => Expect::string()->castTo(fn ($v) => Foo::fromString($v));
  'foo2' => Expect::string()->castTo('Foo::fromString');
});

I'm willing to make a PR for this if you accept the feature to be integrated in the project.

@JanTvrdik
Copy link
Contributor

JanTvrdik commented Mar 8, 2023

The idea is good, but it would be better to use different method name, to more accurately describe the action, e.g. transform (that is the name used by Zod)

@dg dg closed this as completed in efa6fed Oct 3, 2023
dg added a commit that referenced this issue Oct 3, 2023
dg added a commit that referenced this issue Oct 3, 2023
dg added a commit that referenced this issue Oct 4, 2023
dg added a commit that referenced this issue Oct 4, 2023
dg added a commit that referenced this issue Oct 5, 2023
dg added a commit that referenced this issue Oct 5, 2023
dg added a commit that referenced this issue Oct 5, 2023
dg added a commit that referenced this issue Oct 5, 2023
dg added a commit that referenced this issue Oct 5, 2023
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

2 participants