Skip to content

Commit

Permalink
Merge pull request #2 from lukasblaho/master
Browse files Browse the repository at this point in the history
update SerializerFactory to know to create HybridSerializer
  • Loading branch information
pauci authored Apr 10, 2017
2 parents 5419a53 + 23da05f commit acc46ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": "^7.0",
"container-interop/container-interop": "^1.0",
"pauci/cqrs": "^0.2"
"pauci/cqrs": "^0.3"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
Expand Down
4 changes: 4 additions & 0 deletions example/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@
//'instance' => 'my_serializer_alias',
],
],

'event_type_map' => [
'App\Model\Entity\Event\OriginalEvent' => CQRSFactory\Event\RenamedEvent::class,
],
],
];
8 changes: 8 additions & 0 deletions src/Event/RenamedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CQRSFactory\Event;

class RenamedEvent
{
private $name;
}
14 changes: 14 additions & 0 deletions src/SerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CQRSFactory;

use CQRS\Serializer\HybridSerializer;
use CQRS\Serializer\JsonSerializer;
use CQRS\Serializer\SerializerInterface;
use Interop\Container\ContainerInterface;
Expand All @@ -17,6 +18,19 @@ protected function createWithConfig(ContainerInterface $container, string $confi
{
$config = $this->retrieveConfig($container, $configKey, 'serializer');

if ($config['class'] === HybridSerializer::class) {
$dictionary = $config['event_type_map'] ?: [];

/** @var JsonSerializer $jsonSerializer */
$jsonSerializer = new JsonSerializer();

return new $config['class'](
$jsonSerializer,
$dictionary

);
}

return new $config['class'](
is_string($config['instance'])
? $container->get($config['instance'])
Expand Down

0 comments on commit acc46ab

Please sign in to comment.