minor #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
-------
c4415cfd67
Throw an exception when the serializer component is not loaded
This commit is contained in:
commit
8ab7077225
@ -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);
|
||||
|
Reference in New Issue
Block a user