Skip to content

Possibility to validate callback signature #64

Open
@milo

Description

@milo

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions