Search by

jawitold / deprecated-route-bundle

JaWitold

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

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-12-03 19:14 UTC

This package is auto-updated.

Last update: 2026-12-03 19:15:14 UTC


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_arguments at container build time, so there is no reflection at runtime.
  • A kernel.response subscriber 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.