Skip to content

How to upcast events with Prooph #57

Description

@webdevilopers

Came from:

Symfony DI integeration:

services:
  Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator: null

  # Metadata enrichers
  Acme\Common\Infrastructure\Prooph\EventStore\IPAddressMetadataEnricher:
    tags:
      - { name: 'prooph_event_store.default.metadata_enricher' }
    arguments:
      - '@request_stack'
  
  # Upcasters
  Acme\Common\Infrastructure\Prooph\EventStore\Upcaster: ~

  Prooph\EventStore\Plugin\UpcastingPlugin:
    arguments: ['@Acme\Common\Infrastructure\Prooph\EventStore\Upcaster']
    tags:
      - { name: 'prooph_event_store.default.plugin' }

The Upcaster implementation:

<?php

namespace Acme\Common\Infrastructure\Prooph\EventStore;

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\Upcasting\SingleEventUpcaster;

final class Upcaster extends SingleEventUpcaster
{
    public function upcast(Message $message): array
    {
        dd($message);
    }

    protected function canUpcast(Message $message): bool
    {
        dd(__METHOD__);
    }

    protected function doUpcast(Message $message): array
    {
        dd(__METHOD__);
    }
}

Using the class already provided by Prooph:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions