Skip to content

Commit 8ab7077

Browse files
committed
minor symfony#28451 [Messenger] Throw an exception when the serializer component 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
2 parents 839dc26 + c4415cf commit 8ab7077

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Messenger\Envelope;
1515
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
16+
use Symfony\Component\Messenger\Exception\RuntimeException;
1617
use Symfony\Component\Serializer\Encoder\JsonEncoder;
1718
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1819
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@@ -37,6 +38,10 @@ public function __construct(SymfonySerializerInterface $serializer, string $form
3738

3839
public static function create(): self
3940
{
41+
if (!class_exists(SymfonySerializer::class)) {
42+
throw new RuntimeException(sprintf('The default Messenger Serializer requires Symfony\'s Serializer component. Try running "composer require symfony/serializer".'));
43+
}
44+
4045
$encoders = array(new XmlEncoder(), new JsonEncoder());
4146
$normalizers = array(new ObjectNormalizer());
4247
$serializer = new SymfonySerializer($normalizers, $encoders);

0 commit comments

Comments
 (0)