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
-------

f27c15a493 [Messenger] added a simple serializer
This commit is contained in:
Fabien Potencier 2018-09-08 14:15:33 +02:00
commit 9af885cde4

View File

@ -13,6 +13,10 @@ namespace Symfony\Component\Messenger\Transport\Serialization;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
use Symfony\Component\Serializer\SerializerInterface;
/**
@ -31,6 +35,15 @@ class Serializer implements DecoderInterface, EncoderInterface
$this->context = $context;
}
public static function create(): self
{
$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new SymfonySerializer($normalizers, $encoders);
return new self($serializer);
}
/**
* {@inheritdoc}
*/