PHP code example of spriebsch / longbow

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

    

spriebsch / longbow example snippets


use spriebsch\DomainEvent\AbstractId;
use spriebsch\DomainEvent\DomainEvent;
use spriebsch\DomainEvent\MapToTopic;
use spriebsch\DomainEvent\UseAsCorrelationId;

final readonly class OrderId extends AbstractId
{
}

#[MapToTopic('acme.sales.order.order-placed')]
final readonly class OrderPlaced implements DomainEvent
{
    public function __construct(
        private OrderId $orderId,
        public string $product,
    ) {
    }

    #[UseAsCorrelationId]
    public function orderId(): OrderId
    {
        return $this->orderId;
    }
}

Longbow::configure($configuration, ApplicationFactory::class);

public function handle(PlaceOrder $command): DomainEvent
{
    $event = new OrderPlaced(OrderId::generate(), $command->product);
    $this->eventWriter->store($event);

    return $event;
}

final readonly class SalesEvents extends EventStream
{
    protected function topics(): array
    {
        return [Topic::fromString('acme.sales.order.order-placed')];
    }
}