Skip to content

[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

Merged
merged 1 commit into from
Aug 14, 2023
Merged

[Messenger] HandlerArgumentsStamp #17174

merged 1 commit into from
Aug 14, 2023

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Aug 14, 2022

@carsonbot carsonbot added this to the 6.2 milestone Aug 14, 2022
fabpot added a commit to symfony/symfony that referenced this pull request Aug 14, 2022
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
@alexislefebvre
Copy link
Contributor

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.

@OskarStark
Copy link
Contributor

friendly ping @enumag

@enumag
Copy link
Contributor Author

enumag commented Nov 4, 2022

Code sample and version note added.

@enumag enumag force-pushed the patch-4 branch 5 times, most recently from 52a946f to 187f63f Compare November 4, 2022 09:25
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
available in the handler.
available in the handler::

messenger.rst Outdated
}
}

Then your handler will look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The HandlerArgumentsStamp was introduced in Symfony 6.2.
The :class:`Symfony\\Component\\Messenger\\Stamp\\HandlerArgumentsStamp` was introduced in Symfony 6.2.

@OskarStark OskarStark changed the base branch from 6.2 to 6.3 August 14, 2023 08:01
@OskarStark
Copy link
Contributor

It took time, but here we go, this is in now. Thank you very much Jáchym.

@OskarStark OskarStark merged commit 3da709d into symfony:6.3 Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants