symfony/routing
Symfony Routing maps HTTP requests to configuration variables via flexible route definitions. Match incoming paths to controllers and parameters, and generate URLs from named routes using RouteCollection, UrlMatcher, UrlGenerator, and RequestContext.
symfony/routing package is a fundamental component for Laravel applications, aligning with Laravel’s built-in routing system (e.g., Illuminate\Routing). It provides low-level URL matching/generation capabilities, which can replace or augment Laravel’s routing layer for custom use cases (e.g., API gateways, microservices, or legacy system integrations).UrlMatcher, UrlGenerator, RouteCollection) allows for granular integration—TPMs can leverage it to:
Illuminate\Routing\Router) is built on Symfony’s routing (via symfony/routing under the hood). Direct integration is highly feasible but requires careful abstraction to avoid conflicts.Route::get(), Route::resource(), etc.#Route annotations.Request object.symfony/routing for non-critical routes (e.g., admin panels, APIs) before full replacement.RouteCollection alongside Laravel’s router via service providers or facades.symfony/routing (v6.x). Upgrading to v7/8 is backward-compatible for most use cases.routes/web.php) are not directly affected, but custom loaders may need updates.#[Route] vs. Laravel’s #Route).RouteCompiler) can outperform Laravel’s router in high-load scenarios but may require cache warming in serverless environments.RouteCollection or PHP attributes?)Route objects vs. Laravel’s Route instances)Laravel Ecosystem:
symfony/routing alongside Laravel’s router (e.g., SymfonyRoutingServiceProvider).UrlGenerator/UrlMatcher via Laravel’s facade pattern (e.g., Routing::generate()).RouteCompiler for pre-compiled routes in production.RouteCollection to dynamically inject routes (e.g., tenant-aware routing).Non-Laravel Systems:
UrlGenerator to resolve dynamic URLs in resolvers.| Phase | Action | Tools/Dependencies |
|---|---|---|
| Assessment | Audit current routes (YAML/PHP) for Symfony compatibility. | php artisan route:list |
| Pilot | Replace 1–2 routes (e.g., /api/v1/*) with symfony/routing. |
RouteCollection, UrlMatcher |
| Hybrid Mode | Use Symfony for custom logic (e.g., regex routes) while keeping Laravel for standard routes. | Service Provider, Facade |
| Full Migration | Replace Laravel’s router entirely (if justified). | Custom Router class extending UrlMatcher |
| Optimization | Enable Symfony’s compiled routes and cache warming. | php artisan route:cache (custom command) |
RouteCollection or PHP arrays.#Route (v8+) or Laravel’s #Route with a shared loader.Route class for runtime-generated routes (e.g., user-specific paths).Request object with Symfony’s RequestContext (host, scheme, base URL).$context = new RequestContext();
$context->fromRequest($request); // Laravel Request → Symfony RequestContext
Route objects can be adapted to Laravel’s middleware via Route::getController().$route = $matcher->match($request);
$controller = $route['_controller'];
app()->make($controller)->handle($request);
route('name') with UrlGenerator::generate() for non-critical paths.UrlMatcher to validate incoming requests before Laravel’s router.Route objects to Laravel’s middleware pipeline.Illuminate\Routing in favor of Symfony’s components.RouteCollection centralizes route definitions.routing:debug command alongside Laravel’s route:list.ResourceNotFoundException to Laravel’s 404 responses.symfony/routing/loader for YAML/JSON).php artisan route:warm).How can I help you explore Laravel packages today?