Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor #28451 [Messenger] Throw an exception when the serializer compo…
…nent is not loaded (sroze)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] Throw an exception when the serializer component is not loaded

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ø
| License       | MIT
| Doc PR        | ø

This adds a sensible exception when trying to build the class without the Symfony Serializer component.

Commits
-------

c4415cf Throw an exception when the serializer component is not loaded
  • Loading branch information
fabpot committed Sep 12, 2018
2 parents 839dc26 + c4415cf commit 8ab7077
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Messenger\Exception\RuntimeException;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand All @@ -37,6 +38,10 @@ public function __construct(SymfonySerializerInterface $serializer, string $form

public static function create(): self
{
if (!class_exists(SymfonySerializer::class)) {
throw new RuntimeException(sprintf('The default Messenger Serializer requires Symfony\'s Serializer component. Try running "composer require symfony/serializer".'));
}

$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new SymfonySerializer($normalizers, $encoders);
Expand Down

0 comments on commit 8ab7077

Please sign in to comment.