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

Possibility to validate callback signature #64

Open
milo opened this issue Apr 30, 2024 · 1 comment
Open

Possibility to validate callback signature #64

milo opened this issue Apr 30, 2024 · 1 comment

Comments

@milo
Copy link
Member

milo commented Apr 30, 2024

Hi,

time to time I would like to validate callback signature and/or its return value. In some scenarios you setup hook and such hook invocation may throw TypeError lately because of incompatible signature. Another case is that you have to check type of returned value from callback in runtime. Both of such cases could be validated in setup time for example by:

Expect::signature(fn(int $level): string => '');

Such "signature validation" can by done by PHP typesystem itself by interface:

interface LogLevelTranslator
{
    function __invoke(int $level): string;
}

and it is probably cleaner way but too verbose.

Would you consider to merge such functionality? Or maybe into Nette\Utils\Validators?

@dg
Copy link
Member

dg commented May 3, 2024

Expect::signature() looks useful. Type validation could probably be handled with this https://doc.nette.org/en/utils/type#toc-allows

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