Description
EventDispatcherTask ignores its required event_name option: the event is dispatched under its class name only, so listeners registered on the configured event name are never called.
Reproduction
# Task configuration level
code:
service: '@CleverAge\ProcessBundle\Task\Event\EventDispatcherTask'
options:
event_name: 'myapp.myevent'
#[AsEventListener(event: 'myapp.myevent')]
public function onMyEvent(EventDispatcherTaskEvent $event): void
{
// never called
}
With a dispatcher listening on both names, only the class-name listener is called:
listener on EventDispatcherTaskEvent::class called
Tested on main (f8201fe), PHP 8.5, Symfony 7.4.
Cause
EventDispatcherTask::execute() calls:
$this->eventDispatcher->dispatch($event);
$options['event_name'] is required and validated but never used. It is a regression from a833456 ("ecs/rector/phpstan", 2023-03-12). Before that commit, the call was dispatch($event, $options['event_name']). The bug has shipped in every release since v4.0.
Proposed fix
$this->eventDispatcher->dispatch($event, $options['event_name']);
It restores the documented behaviour (see docs/reference/tasks/event_dispatcher_task.md, which uses event_name: 'myapp.myevent'). I also suggest adding unit tests and completing the empty event_name description in the reference doc.
Requirements
- Documentation updates
- [] Unit tests
Breaking changes
Minor: since v4.0, the only way to receive the event was to listen on CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent. After the fix, those listeners will stop being called unless event_name is set to that class name. If the maintainers prefer to avoid any break, the task could dispatch under both names during a deprecation period.
Description
EventDispatcherTaskignores its requiredevent_nameoption: the event is dispatched under its class name only, so listeners registered on the configured event name are never called.Reproduction
With a dispatcher listening on both names, only the class-name listener is called:
Tested on
main(f8201fe), PHP 8.5, Symfony 7.4.Cause
EventDispatcherTask::execute()calls:$options['event_name']is required and validated but never used. It is a regression from a833456 ("ecs/rector/phpstan", 2023-03-12). Before that commit, the call wasdispatch($event, $options['event_name']). The bug has shipped in every release since v4.0.Proposed fix
It restores the documented behaviour (see
docs/reference/tasks/event_dispatcher_task.md, which usesevent_name: 'myapp.myevent'). I also suggest adding unit tests and completing the emptyevent_namedescription in the reference doc.Requirements
Breaking changes
Minor: since v4.0, the only way to receive the event was to listen on
CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent. After the fix, those listeners will stop being called unlessevent_nameis set to that class name. If the maintainers prefer to avoid any break, the task could dispatch under both names during a deprecation period.