bengor-user/symfony-routing-bridge-bundle
Since this bundle is Symfony-focused, Laravel developers must bridge it via Symfony's components (e.g., symfony/routing). Start by installing the required Symfony packages:
composer require symfony/routing symfony/http-foundation
Then, install the bundle (via Composer) and manually integrate its routing logic into Laravel’s RouteServiceProvider:
// config/app.php
'providers' => [
// ...
App\Providers\SymfonyRoutingBridgeServiceProvider::class,
],
Leverage the bundle to generate routes dynamically based on authenticated user roles. Example:
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
// In a Laravel controller or service
$router = app(SymfonyRoutingBridgeBundle::class);
$url = $router->generate('user_profile', [
'_user' => auth()->user()->id,
], UrlGeneratorInterface::ABSOLUTE_URL);
Use the bundle to enforce route access via user roles. Extend Laravel’s RouteServiceProvider to integrate Symfony’s route matching:
// app/Providers/RouteServiceProvider.php
public function boot()
{
parent::boot();
$this->app->make(SymfonyRoutingBridgeBundle::class)
->addRouteCollection($this->router->getRoutes());
}
Pass user-specific data (e.g., user_id) as route parameters:
// In a controller
$route = $this->router->generate('user_dashboard', [
'_user' => auth()->id(),
'_locale' => app()->getLocale(),
]);
Combine with Laravel middleware to validate routes before execution:
// app/Http/Kernel.php
protected $routeMiddleware = [
'role' => \App\Http\Middleware\CheckUserRole::class,
];
Cache Symfony route collections for performance:
// In a service
$cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
$routeCollection = $cache->get('symfony_routes', function() {
return $this->router->getRouteCollection();
});
route_name while Laravel uses route('name'). Ensure consistency:
// Symfony-style route definition (in config/routes.yaml)
user_profile:
path: /profile/{_user}
defaults: { _controller: App\Controller\UserController::profile }
Request object differs from Laravel’s. Use a wrapper:
$symfonyRequest = new \Symfony\Component\HttpFoundation\Request(
$_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER
);
generate() fails, check:
_user) are provided.$this->router->setDebug(true);
// app/SymfonyRoutingBridgeExtension.php
public function loadRoutes(RouteCollection $collection)
{
foreach (Route::getRoutes() as $route) {
$collection->add($route->getName(), $route->getCompiler()->getRoute());
}
}
$modifiedRoutes = clone $originalRoutes;
spatie/laravel-routing for modern Laravel.How can I help you explore Laravel packages today?