Route
in package
Lightweight route collection with a fluent, instance‑based API.
Example:
$router = (new Route())
->get('/hello', static fn () => 'Hello World')
->post('/users', [$controller, 'store']);
$routes = $router->all();
Table of Contents
- GET = 'GET'
- OPTIONS = 'OPTIONS'
- PATCH = 'PATCH'
- POST = 'POST'
- PUT = 'PUT'
- $routes : array<string|int, mixed>
- get() : self
- getAll() : array<string|int, mixed>
- Retrieve all registered routes.
- post() : self
- put() : self
- add() : self
- normalizePath() : string
Constants
GET
public
mixed
GET
= 'GET'
OPTIONS
public
mixed
OPTIONS
= 'OPTIONS'
PATCH
public
mixed
PATCH
= 'PATCH'
POST
public
mixed
POST
= 'POST'
PUT
public
mixed
PUT
= 'PUT'
Properties
$routes
private
array<string|int, mixed>
$routes
= []
array<int, array{method:string, path:string, handler:callable}>
Methods
get()
public
get(string $path, mixed $handler) : self
Parameters
- $path : string
- $handler : mixed
Return values
self —getAll()
Retrieve all registered routes.
public
getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —post()
public
post(string $path, mixed $handler) : self
Parameters
- $path : string
- $handler : mixed
Return values
self —put()
public
put(string $path, mixed $handler) : self
Parameters
- $path : string
- $handler : mixed
Return values
self —add()
private
add(string $method, string $path, mixed $handler) : self
Parameters
- $method : string
- $path : string
- $handler : mixed
Return values
self —normalizePath()
private
normalizePath(string $path) : string
Parameters
- $path : string