Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9af885c

Browse files
committed
feature #28400 [Messenger] Add a simple serializer (fabpot)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Messenger] Add a simple serializer | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | #... When using the Messenger component without Symfony full stack, it helps to use a simple Serializer configured with the bare minimum (this bare minimum is up to the discussion). Commits ------- f27c15a [Messenger] added a simple serializer
2 parents a480dc6 + f27c15a commit 9af885c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
use Symfony\Component\Messenger\Envelope;
1515
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
16+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
17+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
18+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
19+
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
1620
use Symfony\Component\Serializer\SerializerInterface;
1721

1822
/**
@@ -31,6 +35,15 @@ public function __construct(SerializerInterface $serializer, string $format = 'j
3135
$this->context = $context;
3236
}
3337

38+
public static function create(): self
39+
{
40+
$encoders = array(new XmlEncoder(), new JsonEncoder());
41+
$normalizers = array(new ObjectNormalizer());
42+
$serializer = new SymfonySerializer($normalizers, $encoders);
43+
44+
return new self($serializer);
45+
}
46+
3447
/**
3548
* {@inheritdoc}
3649
*/

0 commit comments

Comments
 (0)