Skip to content

Inject route parameters as controller method arguments #356

@philipobenito

Description

@philipobenito

Allow route parameters to be injected directly as controller method arguments rather than requiring the $args array.

Current behaviour:

$router->map('GET', '/users/{id}', function (ServerRequestInterface $request, array $args) {
    $id = $args['id'];
});

Proposed behaviour (via strategy or opt-in):

$router->map('GET', '/users/{id}', function (ServerRequestInterface $request, string $id) {
    // $id injected directly
});

Considerations:

  • Requires reflection to inspect controller signatures, which has performance overhead
  • The ServerRequestInterface injection should remain optional
  • Should be implemented as a strategy concern, not in the routing core
  • Edge cases around parameter naming mismatches, default values, and variadic parameters
  • Could be a companion package rather than core feature

Target: 7.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions