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

Skip to content

Commit 4b1b74f

Browse files
committed
[Messenger] added a simple serializer
1 parent f2f4cd8 commit 4b1b74f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\Serializer\Encoder\JsonEncoder;
16+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
17+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
18+
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
19+
20+
class SimpleSerializer implements EncoderInterface, DecoderInterface
21+
{
22+
private $serializer;
23+
24+
public function __construct()
25+
{
26+
$encoders = array(new XmlEncoder(), new JsonEncoder());
27+
$normalizers = array(new ObjectNormalizer());
28+
$serializer = new SymfonySerializer($normalizers, $encoders);
29+
$this->serializer = new Serializer($serializer);
30+
}
31+
32+
public function decode(array $encodedEnvelope): Envelope
33+
{
34+
return $this->serializer->decode($encodedEnvelope);
35+
}
36+
37+
public function encode(Envelope $envelope): array
38+
{
39+
return $this->serializer->encode($envelope);
40+
}
41+
}

0 commit comments

Comments
 (0)