Skip to content

Support for typed route parameters #69

Open
@fabiante

Description

@fabiante

Hi!

I'd like to use php-di to inject route parameters. In my case these are always of type int.

Using this function signature ...

$app->delete("/objects/{objectId}", [MyController::class, 'deleteObject']); // Please ignore the fake callable setup, this is just for demonstration

// ...

public function deleteObject(Request $request, Response $response, int $objectId)

... and then calling the path of this function with this URL: DELETE /objects/testing/ ...

... produces a standard PHP exception: Argument 4 passed to App\\Controllers\\v2\\DocumentClassController::deleteTableField() must be of the type int, string given

I do understand why this happens and of course I could remove the int type from the function signature and perform my own validation. But' maybe I am missing a more elegant way to catch this exception and automatically respond with a 400 status code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions