On the SitePoint PHP blog there's a tutorial posted that wants to help demystify the command bus design pattern with the help of the Tactician package, a part of the packages from The PHP League.
Command Buses have been getting a lot of community attention lately. The topic can be quite overwhelming at first when trying to understand all the concepts and terminology, but in essence – what a Command Bus does is actually incredibly simple.In this article, we’ll take a closer look at variations of the Command Pattern; their components; what a Command Bus is; and an example application using the Tactician package.
The article starts with a look at what the Command Bus design pattern is and where it could be put to use in an application. There's a bit of sample code showing how to implement a basic bus and the commands it would be used to execute. Their example application uses a "deck of cards" set of actions. They show how to use the Tactician library to build and execute three related commands: CreateDeck
, ShuffleDeck
and DrawCard
. They show you how to build out the pieces you'll need - the extractor, locator and middleware - and join them all together to execute the commands.