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],
];
Database Setup
Run migrations to create the route_usage table:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case Trigger the route tracking by visiting your application or running tests. Then inspect usage:
php bin/console show-route-usage
show-route-usage → Lists all routes with last usage timestamps.show-dead-routes → Flags routes unused for a configurable threshold (default: 30 days).route_usage stores route calls with timestamps.config/packages/symfony_route_usage.yaml (if manually configured).Development Workflow
show-dead-routes after refactoring to identify removable routes.CI/CD Integration
php bin/console show-dead-routes --days=90
Testing
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']);
}
config/packages/symfony_route_usage.yaml:
symfony_route_usage:
dead_route_days: 60 # Routes unused for >60 days are flagged
symfony_route_usage:
ignored_routes:
- '^/health'
- '^/_profiler'
RouteUsage service in tests.Database Dependencies
composer.json scripts:
"post-install-cmd": [
"php bin/console doctrine:migrations:migrate --no-interaction"
]
route_usage table existence with:
php bin/console doctrine:schema:validate
Route Caching
php bin/console cache:clear
Ignored Routes Misconfiguration
^/).php bin/console debug:router | grep "ignored route"
Performance Overhead
symfony_route_usage:
enabled: "%kernel.environment% != 'prod'"
SymfonyRouteUsageBundle is loaded:
php bin/console debug:container symfony_route_usage.route_usage
bundles.php or missing dependencies.Custom Storage
RouteUsageStorage service to use Redis or Elasticsearch:
services:
symfony_route_usage.route_usage.storage:
class: App\Service\RedisRouteUsageStorage
arguments: ['@redis']
Symplify\SymfonyRouteUsage\Contract\RouteUsageStorageInterface.Event Listeners
kernel.request:
// src/EventListener/RouteUsageListener.php
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) return;
$this->routeUsage->record($event->getRequest()->getPathInfo());
}
API Endpoint
// src/Controller/RouteUsageController.php
public function getUsage(RouteUsage $routeUsage)
{
return $this->json($routeUsage->findAll());
}
How can I help you explore Laravel packages today?