Skip to content

EventDispatcherTask ignores the event_name option #189

Description

@Tmalboeuf-CA

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
    • Reference
    • Cookbooks
    • Changelog
  • [] 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions