Download the PHP package phphd/pipeline-bundle without Composer
On this page you can find all versions of the php package phphd/pipeline-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phphd/pipeline-bundle
More information about phphd/pipeline-bundle
Files in phphd/pipeline-bundle
Package pipeline-bundle
Short Description Chain of Responsibility on top of Symfony Messenger
License MIT
Informations about the package pipeline-bundle
PhdPipelineBundle
🧰 Provides Symfony Messenger middleware for basic per-bus pipelining. It enables streamlined chaining of the messages created by message handlers. For instance, when handler (hdl1) processes message (msg1), it creates a subsequent message (msg2), triggering the invocation of the next handler (hdl2), which may, in turn, produce yet another new message, and this cycle continues.
Installation 📥
-
Install via composer
- Enable the bundle in the
bundles.php
Configuration ⚒️
To leverage chain of pipelined handlers for your command/query buses,
you should add phd_pipeline.forward_chain
middleware to the list:
Usage 🚀
Consider having this original message that is initially dispatched to the message bus:
Thy upfront message handler returns a new message that will be used for subsequent redispatch:
The new created message conveys basically the same business concept, but on the higher level of abstraction than
initially. Thereof, instead of scalar types, it has business objects (e.g. VacationType
entity instead
of $vacationTypeId
scalar). Basically, new class no longer merely represents the DTO. It now embodies the complete
domain object.
You should add #[NextForwarded]
attribute to enable forwarding of this new message to the next handler:
Messages lacking
#[NextForwarded]
attribute will not be forwarded. This attribute must be put on each message expected of redispatching.
Finally, one ultimate handler must implement the core business logic. It may or may not return a result to the calling code.
You may chain as many message handlers as needed, even in a recursive manner, by returning an instance of the same class as the original message, provided that it has the forwarding attribute enabled.
Extended forwarding
If you don't want to use the attribute on the message class, you don't have to. There could be some cases when you'd
like to apply some dynamic configurations for NextForwarded
instance. In such cases, you can return an instance of
NextForwarded
class right from the handler method:
The code above is no different from the one shown earlier.
All versions of pipeline-bundle with dependencies
symfony/messenger Version ^6.3.5 | ^7.0
symfony/dependency-injection Version ^6.0 | ^7.0
symfony/http-kernel Version ^6.0 | ^7.0