@@ -50,11 +50,15 @@ serialized::
50
50
51
51
.. _messenger-handler :
52
52
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
+
53
58
A 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)::
58
62
59
63
// src/MessageHandler/SmsNotificationHandler.php
60
64
namespace App\MessageHandler;
@@ -71,6 +75,12 @@ message class (or a message interface) or you can create a class without the att
71
75
}
72
76
}
73
77
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
+
74
84
Thanks to :ref: `autoconfiguration <services-autoconfigure >` and the ``SmsNotification ``
75
85
type-hint, Symfony knows that this handler should be called when an ``SmsNotification ``
76
86
message 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
1770
1780
Customizing Handlers
1771
1781
--------------------
1772
1782
1773
- .. _messenger-handler-config :
1783
+ Configuring Handlers Using Attributes
1784
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1785
+
1786
+ .. versionadded :: 5.4
1774
1787
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.
1777
1790
1778
- You can configure your handler easily by passing options to the attribute::
1791
+ You can configure your handler by passing options to the attribute::
1779
1792
1780
1793
// src/MessageHandler/SmsNotificationHandler.php
1781
1794
namespace App\MessageHandler;
@@ -1793,7 +1806,6 @@ You can configure your handler easily by passing options to the attribute::
1793
1806
}
1794
1807
}
1795
1808
1796
-
1797
1809
Possible options to configure with the attribute are:
1798
1810
1799
1811
* ``bus ``
@@ -1802,6 +1814,8 @@ Possible options to configure with the attribute are:
1802
1814
* ``method ``
1803
1815
* ``priority ``
1804
1816
1817
+ .. _messenger-handler-config :
1818
+
1805
1819
Manually Configuring Handlers
1806
1820
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1807
1821
0 commit comments