Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,40 @@ You can add multiple ``#[AsEventListener()]`` attributes to configure different
}
}

:class:`Symfony\\Component\\EventDispatcher\\Attribute\\AsEventListener`
can also be applied to methods directly::

namespace App\EventListener;

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

final class MyMultiListener
{
#[AsEventListener()]
public function onCustomEvent(CustomEvent $event): void
{
// ...
}

#[AsEventListener(event: 'foo', priority: 42)]
public function onFoo(): void
{
// ...
}

#[AsEventListener(event: 'bar')]
public function onBarEvent(): void
{
// ...
}
}

.. note::

You can notice that the attribute doesn't require its ``event``
parameter to be set if the method already type-hints the
expected event.

.. _events-subscriber:

Creating an Event Subscriber
Expand Down