mini\Router\Reroute class

Documentation

Exception for pattern-based routing in DEFAULT.php files

Allows DEFAULT.php to define routing patterns for its directory scope. The Router will match the current path against patterns and resolve the target.

Only valid when thrown from DEFAULT.php files. Patterns are relative to the directory containing the DEFAULT.php.

Pattern targets can be:

  • string: Request path (Router will resolve to file)
  • Closure: Invoked with path parameters, returns request path string
  • ResponseInterface: Direct response (future)
  • RequestHandlerInterface: PSR-15 handler (future)

IMPORTANT: Targets are REQUEST PATHS, not filenames! Router resolves them: _view?id=123 → tries [_view.php, __DEFAULT__.php]

Examples:

// _routes/users/__DEFAULT__.php
throw new Reroute([
    '/{id}/' => fn($id) => "_view?id=$id",      // → resolves to _view.php
    '/{id}/edit' => '_edit',                     // → resolves to _edit.php
    '/create' => '_create',                      // → resolves to _create.php
    '/' => '_index',                             // → resolves to _index.php
]);

// _routes/blog/__DEFAULT__.php
throw new Reroute([
    '/{slug}/' => fn($slug) => "_post?slug=$slug",  // → resolves to _post.php
    '/' => 'index',                                  // → resolves to blog/index.php
]);

Security: Can route to underscore-prefixed files (internal routing).

Inheritance

Extends: RuntimeException

Implements: Stringable Throwable

Properties (5)

public readonly array $routes
protected mixed $message
protected mixed $code
protected string $file
protected int $line

Methods (10)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Source

src/Router/Reroute.php:46-57