PHP code example of andreo / eventsauce-messenger

1. Go to this page and download the library: Download andreo/eventsauce-messenger 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/ */

    

andreo / eventsauce-messenger example snippets



use Andreo\EventSauce\Messenger\EventConsumer\InjectedHandleMethodInflector;
use EventSauce\EventSourcing\EventConsumption\EventConsumer;
use EventSauce\EventSourcing\EventConsumption\HandleMethodInflector;
use Andreo\EventSauce\Messenger\Attribute\AsEventSauceMessageHandler;
use EventSauce\EventSourcing\Message;

final class FooBarBazMessageHandler extends EventConsumer
{
    // copy-paste trait for inject HandleMethodInflector of EventSauce
    // This example use EventSauce\EventSourcing\EventConsumption\InflectHandlerMethodsFromType. Remember, register your way
    use InjectedHandleMethodInflector;

    public function __construct(
        private HandleMethodInflector $handleMethodInflector
    )
    {}

    #[AsEventSauceMessageHandler(bus: 'eventBus')]
    public function onFooCreated(FooCreated $fooCreated, Message $message): void
    {
    }

    // You can define more handlers also union types(only with InflectHandlerMethodsFromType) if you want as below
    #[AsEventSauceMessageHandler(bus: 'eventBus')]
    public function onBarOrBazCreated(BarCreated|BazCreated $barCreated, Message $message): void
    {
    }
}


use Andreo\EventSauce\Messenger\DependencyInjection\RegisterEventSauceMessageHandlerAttribute;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    protected function build(ContainerBuilder $container): void
    {
        RegisterEventSauceMessageHandlerAttribute::register($container);
    }
}