Using the CQRS design pattern
In the Legacy core, all the controllers use the ObjectModel
child classes to manage the interactions with the database for reading and writing. Whereas in the Symfony modern controller, the core uses the CQRS design pattern with the Command
and Query
objects.
Using a Command object and its CommandHandler class in the CommandBus
If you have to do an UPDATE
, DELETE
, or INSERT
action in the database, you mustn’t directly call Doctrine and handle it directly inside the controller. Instead, you should use a Command
object that contains the necessary data for your action to be done. Every type of Command
object has a linked CommandHandler
class containing a handle()
method responsible for executing the desired action.
Prestashop uses a CommandBus, managed by a library called Tactician
, which is like a big pipe in which you can put your Commands, and it processes them one by one, matching each Command object
with its CommandHandler
and executing...