Throw an exception when the serializer component is not loaded

This commit is contained in:
Samuel ROZE 2018-09-12 00:01:16 +02:00
parent 839dc2693a
commit c4415cfd67

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Messenger\Transport\Serialization;
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;
@ -37,6 +38,10 @@ class Serializer implements SerializerInterface
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);