Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony Routing Bridge Laravel Package

bengor-user/symfony-routing-bridge

Adapter bridge that integrates BenGorUser’s User library with Symfony Routing, enabling user-related routing compatibility. Install via Composer and run the fully PHPSpec-tested suite locally.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require bengor-user/symfony-routing-bridge
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        BenGorUser\SymfonyRoutingBridge\SymfonyRoutingBridgeServiceProvider::class,
    ],
    
  2. Basic Usage Publish the config file (if needed) and bind Laravel routes to Symfony’s router:

    use BenGorUser\SymfonyRoutingBridge\Facades\SymfonyRouter;
    
    // In a controller or route closure
    $route = SymfonyRouter::getRouteCollection();
    $matcher = SymfonyRouter::getMatcher();
    $generator = SymfonyRouter::getGenerator();
    
  3. First Use Case Convert a Laravel route to a Symfony-compatible URL:

    $url = SymfonyRouter::generate('route.name', ['param' => 'value']);
    

Implementation Patterns

Core Workflows

  1. Route Matching Use Symfony’s matcher to analyze incoming requests:

    $request = app('request');
    $context = SymfonyRouter::getContext();
    $matchResult = SymfonyRouter::getMatcher()->match($request->path(), $context);
    
  2. URL Generation Generate absolute/relative URLs from Laravel routes:

    // Absolute URL
    $absoluteUrl = SymfonyRouter::generate('route.name', [], true);
    
    // Relative URL
    $relativeUrl = SymfonyRouter::generate('route.name');
    
  3. Route Collection Integration Merge Laravel’s route collection with Symfony’s:

    $symfonyRoutes = SymfonyRouter::getRouteCollection();
    $laravelRoutes = app('router')->getRoutes();
    
  4. Middleware Integration Leverage Symfony’s route attributes for Laravel middleware:

    // Define middleware in Symfony route attributes
    $route->setDefault('_middleware', ['auth', 'throttle']);
    

Integration Tips

  • Hybrid Routing: Use Symfony’s RouteCollection for complex logic while keeping Laravel’s simplicity for basic routes.
  • API Versioning: Combine Symfony’s route requirements with Laravel’s API resource versioning.
  • Testing: Mock SymfonyRouter in unit tests:
    $this->app->instance('symfony.router', MockSymfonyRouter::class);
    

Gotchas and Tips

Pitfalls

  1. Route Naming Conflicts Ensure Laravel route names (e.g., home.index) don’t clash with Symfony’s reserved names (e.g., _wildcard).

  2. Context Mismatches Symfony’s Context expects specific parameters (e.g., host, scheme). Override defaults:

    $context = SymfonyRouter::getContext();
    $context->setHost('api.example.com');
    
  3. Deprecated Methods The package is outdated (2017). Avoid relying on undocumented methods like SymfonyRouter::getRouter().

  4. CSRF Token Issues Symfony’s UrlGenerator may not handle Laravel’s CSRF tokens. Manually add them:

    $url = SymfonyRouter::generate('route.name') . '?_token=' . csrf_token();
    

Debugging

  • Route Dumping: Use Symfony’s RouteDumper to inspect routes:
    $dumper = new \Symfony\Component\Routing\RouteDumper\HtmlDumper();
    $dumper->dump($symfonyRoutes);
    
  • Log Matching Errors:
    try {
        $matcher->match('/path');
    } catch (\Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
        \Log::error('Route not found: ' . $e->getMessage());
    }
    

Extension Points

  1. Custom Route Loaders Extend SymfonyRouter to load routes from external sources (e.g., database):

    SymfonyRouter::addRouteCollection($customRoutes);
    
  2. Override Generators Replace the default UrlGenerator with a custom implementation:

    $generator = new CustomUrlGenerator($symfonyRoutes, $context);
    SymfonyRouter::setGenerator($generator);
    
  3. Event Listeners Hook into Symfony’s ROUTE_MATCH and ROUTE_GENERATE events via Laravel’s event system:

    event(new SymfonyRouteMatched($matchResult));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor