From 8c8089bbc5611d1a2a6a6eabedd11e949e7f4534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= <3183926+Steveb-p@users.noreply.github.com> Date: Fri, 12 Oct 2018 15:58:03 +0200 Subject: [PATCH 1/2] Add autoconfiguration note for MessageHandlers --- messenger.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/messenger.rst b/messenger.rst index d3d5d5b9fd6..630f977a3d3 100644 --- a/messenger.rst +++ b/messenger.rst @@ -96,6 +96,11 @@ Once you've created your handler, you need to register it: If the message cannot be guessed from the handler's type-hint, use the ``handles`` attribute on the tag. + +If you are using default Symfony configuration with autoconfiguration enabled, +you can also use special interface +``Symfony\Component\Messenger\Handler\MessageHandlerInterface``, which will +cause Symfony to automatically register ``messenger.message_handler`` tag for you. Transports ---------- From 43fa0bc212ee157c2ba8d596559030b5fbe1ec52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= <3183926+Steveb-p@users.noreply.github.com> Date: Mon, 15 Oct 2018 00:43:05 +0200 Subject: [PATCH 2/2] Add MessageHandlerInterface to example --- messenger.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/messenger.rst b/messenger.rst index 630f977a3d3..45d1d7d4c08 100644 --- a/messenger.rst +++ b/messenger.rst @@ -48,8 +48,10 @@ message handler. It's a class with an ``__invoke`` method:: // src/MessageHandler/MyMessageHandler.php namespace App\MessageHandler; + + use Symfony\Component\Messenger\Handler; - class MyMessageHandler + class MyMessageHandler implements MessageHandlerInterface { public function __invoke(MyMessage $message) { @@ -57,7 +59,12 @@ message handler. It's a class with an ``__invoke`` method:: } } -Once you've created your handler, you need to register it: +Message handlers must be registered as services and :doc:`tagged ` +with the ``messenger.message_handler`` tag. If you're using the +:ref:`default services.yaml configuration `, +this is already done for you, thanks to :ref:`autoconfiguration `. + +If you're not using autoconfigure functionality, then you need to register it: .. configuration-block:: @@ -96,11 +103,6 @@ Once you've created your handler, you need to register it: If the message cannot be guessed from the handler's type-hint, use the ``handles`` attribute on the tag. - -If you are using default Symfony configuration with autoconfiguration enabled, -you can also use special interface -``Symfony\Component\Messenger\Handler\MessageHandlerInterface``, which will -cause Symfony to automatically register ``messenger.message_handler`` tag for you. Transports ----------