laminas/laminas-router
Laminas Router provides flexible, composable routing for PHP applications, with HTTP/console route types, route matching and assembly, and integration points for Laminas MVC/Mezzio. Includes CI-tested components and configurable route stacks.
Pros:
laminas-http (PSR-7 compatible), enabling seamless integration with Laravel’s HTTP layer (e.g., Illuminate\Http\Request).HttpRouteInterface → HttpRouteInterface deprecation) reduces technical debt.Cons:
RouteServiceProvider).laminas-http is PSR-7 compliant, Laravel’s Illuminate\Http differs in implementation (e.g., Request vs. Psr\Http\Message\RequestInterface).High: Laravel’s router (Illuminate/Routing) is replacement-compatible with Laminas Router for core functionality (e.g., path matching, middleware binding).
Key Overlaps:
Route::get(), Route::param(), and regex patterns.RouteMatch objects.Gaps:
route('name') requires custom logic (e.g., mapping Laminas RouteMatch to Laravel’s RouteCollection).php artisan route:cache would need customization to leverage Laminas’ optimized B-tree structure.Medium:
3.x) introduce deprecations (e.g., Http\RouteInterface), requiring proactive refactoring.3.16.0; Laravel’s LTS (PHP 8.2+) aligns, but edge cases may arise.Mitigations:
LaminasRouterFacade).Illuminate/Routing.spatie/laravel-permission) that assume native routing?route:list and dd($request->route()) integrate with Laminas’ RouteMatch objects without custom tooling?Laravel Compatibility:
laminas-http as a PSR-7 adapter for Laravel’s Illuminate\Http\Request/Response.Illuminate/Routing/Router with a decorator pattern wrapping Laminas Router.RouteMatch to bind Laravel middleware via app()->middleware().Tooling Alignment:
RouteCacher to serialize Laminas’ router tree.LaminasRouterServiceProvider./api/users) with Laminas Router equivalents.RouteMatch integration with Laravel’s middleware and controllers.Illuminate/Routing/Router to delegate to Laminas Router.RouteServiceProvider to initialize Laminas Router.ab or Laravel Debugbar).| Feature | Laravel Native | Laminas Router | Integration Notes |
|---|---|---|---|
| Path Matching | ✅ Literal/Regex | ✅ Literal/Regex/Tree | Direct parity. |
| HTTP Methods | ✅ GET/POST/etc. | ✅ Method constraints | Use Laminas\Router\Http\Method constraints. |
| Route Parameters | ✅ {user} |
✅ Segment matching | Align parameter naming conventions. |
| Middleware Binding | ✅ $route->middleware() |
❌ (Custom logic needed) | Bind via RouteMatch in a facade. |
| Named Routes | ✅ route('profile') |
❌ | Implement custom resolver. |
| Route Caching | ✅ route:cache |
✅ (B-tree optimized) | Extend Laravel’s RouteCacher. |
| Console Routes | ✅ Artisan commands | ✅ CLI routing | Test CLI route resolution. |
Laminas\Router\Exception vs. Illuminate\Routing\Exceptions).| Risk | Impact | Mitigation |
|---|---|---|
| Route Resolution Errors | 500 errors for invalid paths | Implement fallback to Laravel’s router. |
| Middleware Binding Issues | Broken auth/API validation | Add pre-deployment middleware validation tests. |
| PHP Version Mismatch | Runtime errors (e.g., PHP 8.5+) | Pin Laminas Router to Laravel’s PHP version. |
| Cache Invalidation | Stale routes after deployment | Extend Laravel’s route:clear to flush Laminas cache. |
| Third-Party Package Conflicts | Breaks spatie/laravel-permission |
Test with critical packages pre-release. |
RouteMatch, and Laravel’s DI container.How can I help you explore Laravel packages today?