gember / serializer-symfony
Gember Event Sourcing Serializer adapter based on symfony/serializer
Requires
- php: ^8.3
- gember/event-sourcing: dev-main
- symfony/serializer: ^7.1
Requires (Dev)
- captainhook/captainhook: ^5.23
- friendsofphp/php-cs-fixer: ^3.58
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.1
- rector/rector: ^1.2
- rregeer/phpunit-coverage-check: ^0.3.1
- shipmonk/composer-dependency-analyser: ^1.5
- symfony/property-access: ^7.0
This package is auto-updated.
Last update: 2024-10-12 13:54:08 UTC
README
Gember Event Sourcing Serializer adapter based on symfony/serializer.
All external dependencies in Gember Event Sourcing are organized into separate packages, making it easy to swap out a vendor adapter for another.
Installation
Install with Composer:
composer require gember/serializer-symfony
Configuration
Bind this adapter to the Serializer
interface in your service definitions.
Examples
Vanilla PHP
use Gember\SerializerSymfony\SymfonySerializer; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; $serializer = new SymfonySerializer( new Serializer( [ new DateTimeNormalizer([ DateTimeNormalizer::FORMAT_KEY => 'Y-m-d\TH:i:s.uP', ]), new ObjectNormalizer(), ], [ new JsonEncoder(), ], ), );
Symfony
It is recommended to use the Symfony bundle to configure Gember Event Sourcing. With this bundle, the adapter is automatically set as the default for the Serializer.
If you're not using the bundle, you can either add the serializer to the existing stack of serializers or bind it directly to the Serializer
interface.
Option 1: Add to the existing stack of serializers:
Gember\SerializerSymfony\SymfonySerializer: arguments: - '@serializer' # or any other Symfony Serializer definition of your choice Gember\EventSourcing\Util\Serialization\Serializer\SerializableDomainEvent\SerializableDomainEventSerializer: ~ Gember\EventSourcing\Util\Serialization\Serializer\Serializer: class: Gember\EventSourcing\Util\Serialization\Serializer\Stacked\StackedSerializer arguments: - [ '@Gember\EventSourcing\Util\Serialization\Serializer\SerializableDomainEvent\SerializableDomainEventSerializer', '@Gember\SerializerSymfony\SymfonySerializer' # added to stack of serializers ]
Option 2: Bind directly to Serializer
interface:
Gember\EventSourcing\Util\Serialization\Serializer\Serializer: class: Gember\SerializerSymfony\SymfonySerializer arguments: - '@serializer' # or any other Symfony Serializer definition of your choice