php-ddd
                                
                                 php-ddd copied to clipboard
                                
                                    php-ddd copied to clipboard
                            
                            
                            
                        How to upcast events with Prooph
Came from:
- https://twitter.com/webdevilopers/status/1347197290981818370
Symfony DI integeration:
- https://gist.github.com/webdevilopers/38f1f18576251c99b1cd9aad3753c176
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:
- https://github.com/prooph/event-store/blob/7.x/src/Plugin/UpcastingPlugin.php
Related: https://github.com/prooph/event-store-symfony-bundle/issues/73
Registered Upcaster Plugin is not recognized by Projection