mini\Controller\Router class

Documentation

Controller-level router with type-aware route registration

Provides route matching and parameter extraction for controller methods. Not PSR-15 middleware - returns match information for AbstractController to handle.

Type-aware pattern generation:

  • int $id → {id} becomes (?<id>\d+)
  • string $slug → {slug} becomes (?<slug>[^/]+)
  • float $price → {price} becomes (?<price>\d+.?\d*)

Architecture:

  1. Router::match() finds matching route and extracts URL parameters
  2. Returns array with 'handler' callable and 'params' (type-cast)
  3. AbstractController enriches request with params and creates ConverterHandler
  4. ConverterHandler invokes controller method and converts return value

Properties (1)

private array $routes

Methods (13)

Documentation missing

Register GET route

Register POST route

Register PATCH route

Register PUT route

Register DELETE route

Register route for any method

Import routes from controller method attributes

Add route to registry

Reflect on handler to extract parameter information

Compile path pattern with type-aware regex

Match request to a registered route

Type-cast URL parameters based on route reflection info

Source

src/Controller/Router.php:25-342