Open
Description
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
?
Metadata
Metadata
Assignees
Labels
No labels