-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Messenger] HandlerArgumentsStamp #17174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR was merged into the 6.2 branch. Discussion ---------- [Messenger] Add HandlerArgumentsStamp | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #31075 | License | MIT | Doc PR | symfony/symfony-docs#17174 As discussed in #31075 sometimes it's desirable for the messenger handler to receive additional argument than just the message itself. I understand the voiced concerns about passing the entire envelope but instead of that we could use the approach from this PR which doesn't add any additional arguments by default but is actually even more powerful since it gives the user full control what should be sent to the handler if desired. This is just a prototype of course. With #45377 in mind I used a readonly property from PHP 8.1 but of course such details can be easily adjusted. Let me know if such feature is wanted in Symfony. If yes then I'll add tests and a doc PR. Commits ------- d081267 Add HandlerArgumentsStamp
Can you please add an example of code? I think it also need a note to say that it was added since Symfony 6.2. |
friendly ping @enumag |
Code sample and version note added. |
52a946f
to
187f63f
Compare
messenger.rst
Outdated
It's possible to have messenger pass additional data to the message handler using the | ||
:class:`Symfony\\Component\\Messenger\\Stamp\\HandlerArgumentsStamp`. Add this stamp to | ||
the envelope in a middleware and fill it with any additional data you want to have | ||
available in the handler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
available in the handler. | |
available in the handler:: |
messenger.rst
Outdated
} | ||
} | ||
|
||
Then your handler will look like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then your handler will look like this: | |
Then your handler will look like this:: |
messenger.rst
Outdated
|
||
.. versionadded:: 6.2 | ||
|
||
The HandlerArgumentsStamp was introduced in Symfony 6.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HandlerArgumentsStamp was introduced in Symfony 6.2. | |
The :class:`Symfony\\Component\\Messenger\\Stamp\\HandlerArgumentsStamp` was introduced in Symfony 6.2. |
It took time, but here we go, this is in now. Thank you very much Jáchym. |
Refs