jawitold / deprecated-route-bundle
Symfony bundle that marks controller routes deprecated: RFC 9745 Deprecation + successor Link headers and optional NelmioApiDoc deprecated operations.
Package info
github.com/JaWitold/deprecated-route-bundle
Type:symfony-bundle
pkg:composer/jawitold/deprecated-route-bundle
Requires
- php: >=8.5
- symfony/config: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/event-dispatcher: ^7.4|^8.0
- symfony/http-foundation: ^7.4|^8.0
- symfony/http-kernel: ^7.4|^8.0
- symfony/routing: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- nelmio/api-doc-bundle: ^5.0
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13
Suggests
- nelmio/api-doc-bundle: Marks deprecated routes as deprecated operations in the generated OpenAPI document.
Provides
None
Conflicts
None
Replaces
None
README
Mark Symfony controller routes as deprecated with one attribute. Every response of a deprecated route carries the
RFC 9745 Deprecation header and a Link to its successor, and, when
NelmioApiDocBundle is installed, the OpenAPI operation is marked
deprecated: true.
Typical use: you rename an endpoint (/settings/tag → /settings/tags), keep the old one alive until every client
switches, and want clients and docs to say so.
Installation
composer require jawitold/deprecated-route-bundle
Register the bundle (Symfony Flex does it for you):
// config/bundles.php return [ // ... JaWitold\DeprecatedRouteBundle\JaWitoldDeprecatedRouteBundle::class => ['all' => true], ];
Requires PHP 8.5+ and Symfony 7.4 or 8.x.
Usage
Put #[DeprecatedRoute] on an action, or on the controller class to deprecate all of its actions. The first argument is
the route name of the successor, the second the date the deprecation took effect.
use JaWitold\DeprecatedRouteBundle\Attribute\DeprecatedRoute; class LegacyTagController extends AbstractController { #[DeprecatedRoute('settings_tags_get', '2026-12-03')] #[Route('/settings/tag/{id}', name: 'settings_tag_detail', methods: ['GET'])] public function detail(Tag $tag): JsonResponse { // unchanged } }
GET /settings/tag/7 then answers as before, with:
Deprecation: @1796256000 Link: </settings/tags/7>; rel="successor-version"
The successor URL is generated from the successor route name with the current route parameters, so {id} carries over.
A parameter the successor route does not declare ends up in its query string.
OpenAPI (optional)
With nelmio/api-doc-bundle installed, deprecated operations get deprecated: true and the description starts with:
Deprecated since 2026-12-03, use `GET /settings/tags/{id}`.
Swagger UI shows such operations struck through.
How it works
- A compiler pass reads the attribute from controllers tagged
controller.service_argumentsat container build time, so there is no reflection at runtime. - A
kernel.responsesubscriber adds the headers on main requests whose controller (action, or class as fallback) is deprecated.
Development
composer install vendor/bin/php-cs-fixer fix --dry-run --diff vendor/bin/phpstan analyse vendor/bin/phpunit
License
MIT, see LICENCE.md.