Upcasting

Using events to model software can generate interesting new insights. These insights can cause you to uncover things that you may have wished to have done differently.

Upcasting allows you to transform the raw event data before being turned into event classes. They allow you to make small corrections and fix some mistakes.

In EventSauce upcasting is facilitated in the serialization process. The EventSauce\EventSourcing\Upcasting\UpcastingMessageSerializer class can be used to add one or more upcasting transformations.

Each upcaster must implement the EventSauce\EventSourcing\Upcasting\Upcaster interface:

<?php

namespace EventSauce\EventSourcing\Upcasting;

interface Upcaster
{
    public function upcast(array $message): array;
}

Using multiple upcasters

You can use multiple upcasters using the UpcasterChain.

<?php

use EventSauce\EventSourcing\Upcasting\UpcasterChain;
use EventSauce\EventSourcing\Upcasting\UpcastingMessageSerializer;

$upcastingSerializer = new UpcastingMessageSerializer(
    $actualSerializer,
    new UpcasterChain(new UpcasterOne(), new UpcasterTwo())
);
Frank de Jonge

EventSauce is a project by Frank de Jonge.