Dispatch post write event processor#829
Conversation
| */ | ||
| public function process(mixed $data, Operation $operation, Context $context): mixed | ||
| { | ||
| $data = $this->processor->process($data, $operation, $context); |
There was a problem hiding this comment.
Is it alright for both PreWrite and PostWrite to call "inner" processor? Won't it result on double execution?
There was a problem hiding this comment.
No, I've checked and that was ok. The harder thing is to create tests for that and I have no idea.
| { | ||
| $data = $this->processor->process($data, $operation, $context); | ||
|
|
||
| $operationEvent = $this->operationEventDispatcher->dispatchPostEvent($data, $operation, $context); |
There was a problem hiding this comment.
From naming point of view, does $this->operationEventDispatcher->dispatchPostEvent dispatches it for listeners to listen or it's only a event object factory?
Generally speaking, I cannot understand what's going on with "dispatch event" and "handle event" in two consequent lines of code without reading internals of both.
There was a problem hiding this comment.
Yeah I do not like this part, and that's only to allow developers to switch from resource controller to new operations system easily.
On resource controller:
Pre write
https://github.com/Sylius/SyliusResourceBundle/blob/1.11/src/Bundle/Controller/ResourceController.php#L175
Post write
https://github.com/Sylius/SyliusResourceBundle/blob/1.11/src/Bundle/Controller/ResourceController.php#L202
There was a problem hiding this comment.
In the future, the idea is to handle this with your custom processor or decorating a Sylius one in the e-commerce part when Sylius will use operations.
a77e405 to
aa01fc6
Compare
|
Thanks, Loïc! 🎉 |
Based on #828
Extracted from #817