@@ -50,11 +50,15 @@ serialized::
5050
5151.. _messenger-handler :
5252
53+ ..versionadded ::5.4
54+
55+ The ``#[AsMessageHandler] `` PHP attribute was introduced in Symfony
56+ 5.4. PHP attributes require at least PHP 8.0.
57+
5358A message handler is a PHP callable, the recommended way to create it is to
54- create a class using:class: `Symfony\\ Component\\ Messenger\\ Attribute\\ AsMessageHandler `
55- attribute which has an ``__invoke() `` method that's type-hinted with the
56- message class (or a message interface) or you can create a class without the attribute, by implementing
57- :class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageHandlerInterface `::
59+ create a class that has the:class: `Symfony\\ Component\\ Messenger\\ Attribute\\ AsMessageHandler `
60+ attribute and has an ``__invoke() `` method that's type-hinted with the
61+ message class (or a message interface)::
5862
5963 // src/MessageHandler/SmsNotificationHandler.php
6064 namespace App\MessageHandler;
@@ -71,6 +75,12 @@ message class (or a message interface) or you can create a class without the att
7175 }
7276 }
7377
78+ ..note ::
79+
80+ You can also create a class without the attribute (e.g. if you're
81+ using PHP 7.4), by implementing:class: `Symfony\\ Component\\ Messenger\\ Handler\\ MessageHandlerInterface `
82+ instead.
83+
7484Thanks to:ref: `autoconfiguration <services-autoconfigure >` and the ``SmsNotification ``
7585type-hint, Symfony knows that this handler should be called when an ``SmsNotification ``
7686message is dispatched. Most of the time, this is all you need to do. But you can
@@ -1770,12 +1780,15 @@ on a case-by-case basis via the :class:`Symfony\\Component\\Messenger\\Stamp\\Se
17701780Customizing Handlers
17711781--------------------
17721782
1773- .. _messenger-handler-config :
1783+ Configuring Handlers Using Attributes
1784+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1785+
1786+ ..versionadded ::5.4
17741787
1775- Configuring Handlers Using Attribute
1776- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1788+ The `` #[AsMessageHandler] `` PHP attribute was introduced in Symfony
1789+ 5.4. PHP attributes require at least PHP 8.0.
17771790
1778- You can configure your handlereasily by passing options to the attribute::
1791+ You can configure your handler by passing options to the attribute::
17791792
17801793 // src/MessageHandler/SmsNotificationHandler.php
17811794 namespace App\MessageHandler;
@@ -1793,7 +1806,6 @@ You can configure your handler easily by passing options to the attribute::
17931806 }
17941807 }
17951808
1796-
17971809Possible options to configure with the attribute are:
17981810
17991811* ``bus ``
@@ -1802,6 +1814,8 @@ Possible options to configure with the attribute are:
18021814* ``method ``
18031815* ``priority ``
18041816
1817+ .. _messenger-handler-config :
1818+
18051819Manually Configuring Handlers
18061820~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18071821