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 Route Usage Laravel Package

50bhan/symfony-route-usage

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require symplify/symfony-route-usage
    

    Register the bundle in config/bundles.php if using Symfony Flex:

    return [
        Symplify\SymfonyRouteUsage\SymfonyRouteUsageBundle::class => ['all' => true],
    ];
    
  2. Database Setup Run migrations to create the route_usage table:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. First Use Case Trigger the route tracking by visiting your application or running tests. Then inspect usage:

    php bin/console show-route-usage
    

Where to Look First

  • Console Commands:
    • show-route-usage → Lists all routes with last usage timestamps.
    • show-dead-routes → Flags routes unused for a configurable threshold (default: 30 days).
  • Database Table: route_usage stores route calls with timestamps.
  • Configuration: config/packages/symfony_route_usage.yaml (if manually configured).

Implementation Patterns

Workflows

  1. Development Workflow

    • Use during feature development to track new routes.
    • Run show-dead-routes after refactoring to identify removable routes.
  2. CI/CD Integration

    • Add to deployment pipeline to audit routes post-deploy:
      php bin/console show-dead-routes --days=90
      
    • Fail builds if critical routes are unused (e.g., admin endpoints).
  3. Testing

    • Seed the route_usage table with test data to simulate usage:
      // tests/Functional/RouteUsageTest.php
      public function testRouteUsageTracking()
      {
          $this->client->request('GET', '/test');
          $this->assertDatabaseHas('route_usage', ['path' => '/test']);
      }
      

Integration Tips

  • Symfony Flex: The bundle auto-registers; no manual config needed unless overriding defaults.
  • Custom Thresholds: Adjust dead-route detection in config/packages/symfony_route_usage.yaml:
    symfony_route_usage:
        dead_route_days: 60  # Routes unused for >60 days are flagged
    
  • Exclude Routes: Skip tracking for health checks or internal routes:
    symfony_route_usage:
        ignored_routes:
            - '^/health'
            - '^/_profiler'
    
  • Laravel Adaptation:
    • Use the original Laravel package for Laravel projects.
    • For Symfony/Laravel hybrid apps, mock the RouteUsage service in tests.

Gotchas and Tips

Pitfalls

  1. Database Dependencies

    • Issue: Forgetting to run migrations after installation.
    • Fix: Add to composer.json scripts:
      "post-install-cmd": [
          "php bin/console doctrine:migrations:migrate --no-interaction"
      ]
      
    • Debug: Check for route_usage table existence with:
      php bin/console doctrine:schema:validate
      
  2. Route Caching

    • Issue: Symfony’s route cache may delay tracking updates.
    • Fix: Clear cache after changes:
      php bin/console cache:clear
      
  3. Ignored Routes Misconfiguration

    • Issue: Overly broad ignored routes (e.g., ^/).
    • Fix: Use precise regex patterns and test with:
      php bin/console debug:router | grep "ignored route"
      
  4. Performance Overhead

    • Issue: High-traffic apps may see DB load from tracking.
    • Fix: Disable in production if unused:
      symfony_route_usage:
          enabled: "%kernel.environment% != 'prod'"
      

Debugging

  • Missing Data: Verify the SymfonyRouteUsageBundle is loaded:
    php bin/console debug:container symfony_route_usage.route_usage
    
  • Console Command Errors: Check for typos in bundles.php or missing dependencies.
  • Timestamp Issues: Ensure server time is synchronized (affects "dead route" calculations).

Extension Points

  1. Custom Storage

    • Override the RouteUsageStorage service to use Redis or Elasticsearch:
      services:
          symfony_route_usage.route_usage.storage:
              class: App\Service\RedisRouteUsageStorage
              arguments: ['@redis']
      
    • Implement Symplify\SymfonyRouteUsage\Contract\RouteUsageStorageInterface.
  2. Event Listeners

    • Extend route tracking logic by subscribing to kernel.request:
      // src/EventListener/RouteUsageListener.php
      public function onKernelRequest(GetResponseEvent $event)
      {
          if (!$event->isMasterRequest()) return;
          $this->routeUsage->record($event->getRequest()->getPathInfo());
      }
      
  3. API Endpoint

    • Expose usage data via a custom controller:
      // src/Controller/RouteUsageController.php
      public function getUsage(RouteUsage $routeUsage)
      {
          return $this->json($routeUsage->findAll());
      }
      
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle