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

Skip to content

Commit 31a0ba0

Browse files
committed
[Messenger] added a simple serializer
1 parent f2f4cd8 commit 31a0ba0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Transport\Serialization;
13+
14+
use Symfony\Component\Messenger\Envelope;
15+
use Symfony\Component\Messenger\Transport\Serialization\Serializer as MessengerSerializer;
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;
20+
21+
class SimpleSerializer implements EncoderInterface, DecoderInterface
22+
{
23+
private $serializer;
24+
25+
public function __construct()
26+
{
27+
$encoders = array(new XmlEncoder(), new JsonEncoder());
28+
$normalizers = array(new ObjectNormalizer());
29+
$serializer = new SymfonySerializer($normalizers, $encoders);
30+
$this->serializer = new MessengerSerializer($serializer);
31+
}
32+
33+
public function decode(array $encodedEnvelope): Envelope
34+
{
35+
return $this->serializer->decode($encodedEnvelope);
36+
}
37+
38+
public function encode(Envelope $envelope): array
39+
{
40+
return $this->serializer->encode($envelope);
41+
}
42+
}

0 commit comments

Comments
 (0)