Symfony 8.2 New Published on

Readable subscribers: method and priority

['trace', 100] becomes ['method' => 'trace', 'priority' => 100]: getSubscribedEvents() finally says what each slot holds.

Topics covered: EventDispatcher

New in Symfony 8.2 (in development). getSubscribedEvents() accepted three positional forms, and none of them said what their slots held. You had to know the convention to read ['onFoo', 10], and it was worse with nested arrays. Symfony 8.2 also accepts a named form, everywhere the positional form was accepted.

Before

return [
    KernelEvents::REQUEST => ['onRequest', 10],
    KernelEvents::RESPONSE => [
        ['onEarlyResponse', 100],
        ['onLateResponse', -100],
    ],
];

Since Symfony 8.2

return [
    KernelEvents::REQUEST => ['method' => 'onRequest', 'priority' => 10],
    KernelEvents::RESPONSE => [
        ['method' => 'onEarlyResponse', 'priority' => 100],
        ['method' => 'onLateResponse', 'priority' => -100],
    ],
];

priority is optional and defaults to 0. Both forms can be mixed in the same list, and the old ones keep working.

Your task

Rewrite EtapesSubscriber::getSubscribedEvents() with the named form, without changing the methods or the priorities. The /steps preview shows Steps run: request, trace, signature: the same order as the X-Steps header, which must stay request,trace,signature.

Where the feature comes from: the original pull request.