php-ddd / command
The command part of the Command Query Responsibility Segregation
Installs: 5 640
Dependents: 2
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 1
Open Issues: 0
pkg:composer/php-ddd/command
Requires
- php: >=5.3.3
- php-ddd/domain-event: ~1.0
Requires (Dev)
- fabpot/php-cs-fixer: dev-master
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2025-03-01 19:06:04 UTC
README
This library provides some useful tools in order to create a simple command system.
How it works
// configuration $handler = new AddItemToChartCommandHandler(); $locator = new CommandHandlerLocator(); $locator->register('AddItemToChartCommand', $handler); $bus = new SequentialCommandBus($locator); // usage $command = new AddItemToChartCommand($item, $chart); $bus->dispatch($command); // internally, the bus will call the corresponding handler.
Conventions
We want to follow the Single Responsibility principle. Hence:
- A
CommandHandlercan only handle oneCommandInterface - A
CommandBuswill only dispatch someCommandInterface(and nothing more) - A
CommandHandlerLocatoris responsible of registering associations betweenCommandandCommandHandler
It allows us to force some other conventions like the name of the CommandHandler class that needs to match the
name of the Command it handle. E.g: AddItemToChartCommand will be handled by a AddItemToChartCommandHandler object.