1. Go to this page and download the library: Download macintoshplus/lite-cqrs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
macintoshplus / lite-cqrs example snippets
$userService = new UserService();
$commandBus = new DirectCommandBus()
$commandBus->register('MyApp\ChangeEmailCommand', $userService);
// 1. Setup the Library with InMemory Handlers
$messageBus = new InMemoryEventMessageBus();
$identityMap = new SimpleIdentityMap();
$queue = new EventProviderQueue($identityMap);
$commandBus = new DirectCommandBus(array(
new EventMessageHandlerFactory($messageBus, $queue)
));
// 2. Register a command service and an event handler
$userService = new UserService($identityMap);
$commandBus->register('MyApp\ChangeEmailCommand', $userService);
$someEventHandler = new MyEventHandler();
$messageBus->register($someEventHandler);
$messageBus = new InMemoryEventMessageBus();
$queue = new MyCustomEventQueue();
$commandBus = new DirectCommandBus(array(
new EventMessageHandlerFactory($messageBus, $queue)
));
use LiteCQRS\Bus\MessageHandlerInterface;
class CommandLogger implements MessageHandlerInterface
{
private $next;
public function __construct(MessageHandlerInterface $next)
{
$this->next = $next;
}
public function handle($command)
{
syslog(LOG_INFO, "Executing: " . get_class($command));
$this->next->handle($command);
}
}
$loggerProxyFactory = function($handler) {
return new CommandLogger($handler);
};
$commandBus = new DirectCommandBus(array($loggerProxyFactory));
new \LiteCQRS\Plugin\SymfonyBundle\LiteCQRSBundle(),