Download the PHP package lighthouse/router without Composer
On this page you can find all versions of the php package lighthouse/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lighthouse/router
More information about lighthouse/router
Files in lighthouse/router
Package router
Short Description HTTP Router for the Lighthouse framework
License MIT
Informations about the package router
Lighthouse Router
A fast, simple HTTP router for the Lighthouse framework.
Installation
Requirements
- PHP 8.2 or higher
Features
- Simple, expressive API
- Route parameters with
{param}syntax - Route groups with prefixes
- Named routes for URL generation
- Method-specific routing (GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD)
- PSR-7 request support
Quick Start
Basic Routing
Route Parameters
Parameters are defined with curly braces and automatically extracted:
Route Groups
Group routes with a common prefix:
Nested groups:
Named Routes
Name routes for URL generation:
Multiple Methods
Dispatching Requests
With PSR-7 request:
Or directly with method and path:
Exception Handling
RouteNotFoundException
Thrown when no route matches the request path:
MethodNotAllowedException
Thrown when the path matches but the HTTP method doesn't:
API Reference
Router
| Method | Description |
|---|---|
get(string $path, mixed $handler) |
Register GET route |
post(string $path, mixed $handler) |
Register POST route |
put(string $path, mixed $handler) |
Register PUT route |
patch(string $path, mixed $handler) |
Register PATCH route |
delete(string $path, mixed $handler) |
Register DELETE route |
options(string $path, mixed $handler) |
Register OPTIONS route |
head(string $path, mixed $handler) |
Register HEAD route |
any(string $path, mixed $handler) |
Register route for all methods |
match(array $methods, string $path, mixed $handler) |
Register route for specific methods |
group(string $prefix, callable $callback) |
Create route group |
dispatch(ServerRequestInterface $request) |
Match PSR-7 request |
matchRoute(string $method, string $path) |
Match method and path |
url(string $name, array $params) |
Generate URL for named route |
getRoutes() |
Get all registered routes |
clear() |
Remove all routes |
Route
| Method | Description |
|---|---|
getMethod() |
Get HTTP method |
getPath() |
Get route path |
getHandler() |
Get route handler |
getName() |
Get route name |
name(string $name) |
Set route name |
getParameters() |
Get extracted parameters |
matches(string $method, string $path) |
Check if route matches |
generateUrl(array $params) |
Generate URL with parameters |
RouteMatch
| Method | Description |
|---|---|
getRoute() |
Get matched route |
getHandler() |
Get route handler |
getParameters() |
Get all parameters |
getParameter(string $name, ?string $default) |
Get single parameter |
Testing
License
MIT License. See LICENSE for details.
Part of the Lighthouse Framework
This package is part of the Lighthouse Framework, an educational PHP framework designed to teach how modern frameworks work internally.