1. Go to this page and download the library: Download makinacorpus/corebus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
makinacorpus / corebus example snippets
return [
// ... your other bunbles.
MakinaCorpus\CoreBus\Bridge\Symfony\CoreBusBundle::class => ['all' => true],
];
namespaceApp\Domain\SomeBusiness\Handler;
useMakinaCorpus\CoreBus\CommandBus\AbstractCommandHandler;
finalclassSayHelloHandlerextendsAbstractCommandHandler{
/*
* Method name is yours, you may have more than one handler in the
* same class, do you as wish. Only important thing is to implement
* the Handler interface (here via the AbstractHandler class).
*/publicfunctiondo(SayHelloCommand $command){
echo"Hello, ", $command->name, "\n";
$this->notifyEvent(new HelloWasSaidEvent($command->name));
}
}
namespaceApp\Domain\SomeBusiness\Listener;
useMakinaCorpus\CoreBus\EventBus\EventListener;
finalclassSayHelloListenerimplementsEventListener{
/*
* Method name is yours, you may have more than one handler in the
* same class, do you as wish. Only important thing is to implement
* the EventListener interface.
*/publicfunctionon(HelloWasSaidEvent $event){
$this->logger->debug("Hello was said to {name}.", ['name' => $event->name]);
}
}
namespaceApp\Domain\SomeBusiness\Handler;
useMakinaCorpus\CoreBus\EventBus\EventBusAware;
useMakinaCorpus\CoreBus\EventBus\EventBusAwareTrait;
finalclassSayHelloHandlerimplementsEventBusAware{
useEventBusAwareTrait;
/*
* Method name is yours, you may have more than one handler in the
* same class, do you as wish. Only important thing is to implement
* the Handler interface (here via the AbstractHandler class).
*/#[MakinaCorpus\CoreBus\Attr\CommandHandler]publicfunctiondo(SayHelloCommand $command){
echo"Hello, ", $command->name, "\n";
$this->notifyEvent(new HelloWasSaidEvent($command->name));
}
}
namespaceApp\Domain\SomeBusiness\Listener;
finalclassSayHello{
/*
* Method name is yours, you may have more than one handler in the
* same class, do you as wish. Only important thing is to implement
* the EventListener interface.
*/#[MakinaCorpus\CoreBus\Attr\EventListener]publicfunctionon(HelloWasSaidEvent $event){
$this->logger->debug("Hello was said to {name}.", ['name' => $event->name]);
}
}