[Messenger] ease testing and allow forking the middleware stack#31204
[Messenger] ease testing and allow forking the middleware stack#31204nicolas-grekas merged 1 commit intosymfony:masterfrom
Conversation
b38a927 to
3bdf4b0
Compare
weaverryan
left a comment
There was a problem hiding this comment.
I played with this - works really nicely to solve the problem of a middleware calling handle() multiple times. The middleware needs to know they should clone the stack, but I think that's not a huge issue.
| return $this->iterator = null; | ||
| } | ||
|
|
||
| return $this->stack[] = $this->iterator->current(); |
There was a problem hiding this comment.
I had to stare at this for a minute. When you clone the StackMiddleware, each clone will still maintain this same, one instance of this MiddlewareStack, but will now maintain their own StackMiddleware.offset property (so, that property will move independently). The first StackMiddleware that uses an item from the iterator will use it, but store it on the stack so that it's available when the other StackMiddleware asks for that same $offset.
| /** | ||
| * @internal | ||
| */ | ||
| class MiddlewareStack |
There was a problem hiding this comment.
Can't you simply drop the iterator, store middleware as array in StackMiddleware and advance the pointer manually?
There was a problem hiding this comment.
That would defeat laziness, which is a desired property.
…are stack (nicolas-grekas) This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] ease testing and allow forking the middleware stack | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31179 | License | MIT | Doc PR | - A less radical alternative than #31185 that preserves laziness and addresses the linked issue. Commits ------- 3bdf4b0 [Messenger] ease testing and allow forking the middleware stack
A less radical alternative than #31185 that preserves laziness and addresses the linked issue.