Skip to content

[Messenger] make Envelope first class citizen for middleware handlers #28914

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
Oct 21, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Oct 18, 2018

Q A
Branch? 4.2
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This PR sits on top of #28909 so that only the 2nd commit should be reviewed for now, until I rebase it.
This idea has already been proposed and rejected in #27322.
Yet, now that I've reviewed in depth the component, I politely but strongly suggest to reconsider.
Middleware handlers are the central piece of the routing layer.
When dispatch() accepts object|Envelope, it's because it sits on the outer boundary of the component. handle() on the contrary plugs inside its core routing logic, so that it's very legitimate to require them to deal with Envelope objects. Yes, some middleware care only about the message inside. That's fine calling getMessage() for them.

Right now, we built a complex magic layer that acts as a band-aid just to save this call to getMessage(). For middleware that want the envelope, we require an additional interface that magically changes the expected argument. That's very fragile design: it breaks the L in SOLID...

Looking at the diff stat, this is most natural.

Copy link
Contributor

@ogizanagi ogizanagi left a comment

Choose a reason for hiding this comment

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

Should we remove Envelope::wrap() as in original PR or do you consider it still relevant? We can decide this in another PR though.

@nicolas-grekas nicolas-grekas force-pushed the messenger-envelope-middleware branch 3 times, most recently from fbb0d2a to 881e039 Compare October 20, 2018 18:56
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 20, 2018

Should we remove Envelope::wrap()

yes! same for Envelope->withMessage() as it's unused anymore. Done.

@nicolas-grekas nicolas-grekas force-pushed the messenger-envelope-middleware branch from 881e039 to ae46a43 Compare October 21, 2018 12:55
@nicolas-grekas
Copy link
Member Author

(rebased, ready)

Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

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

You've made @ogizanagi happy. 😄

@sroze
Copy link
Contributor

sroze commented Oct 21, 2018

Thank you @nicolas-grekas.

@sroze sroze merged commit ae46a43 into symfony:master Oct 21, 2018
sroze added a commit that referenced this pull request Oct 21, 2018
…leware handlers (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] make Envelope first class citizen for middleware handlers

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR sits on top of #28909 so that only the 2nd commit should be reviewed for now, until I rebase it.
This idea has already been proposed and rejected in #27322.
Yet, now that I've reviewed in depth the component, I politely but strongly suggest to reconsider.
Middleware handlers are the central piece of the routing layer.
When `dispatch()` accepts `object|Envelope`, it's because it sits on the outer boundary of the component. `handle()` on the contrary plugs inside its core routing logic, so that it's very legitimate to require them to deal with `Envelope` objects. Yes, some middleware care only about the message inside. That's fine calling `getMessage()` for them.

Right now, we built a complex magic layer that acts as a band-aid *just* to save this call to `getMessage()`. For middleware that want the envelope, we require an additional interface that magically *changes* the expected argument. That's very fragile design: it breaks the `L` in `SOLID`...

Looking at the diff stat, this is most natural.

Commits
-------

ae46a43 [Messenger] make Envelope first class citizen for middleware handlers
/**
* @internal
*/
interface NextInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Where it used?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Oct 21, 2018

Choose a reason for hiding this comment

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

In the docblock above, to document the signature of the callable.

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.

6 participants