diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
index bf61e71953..435fe4224d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
@@ -9,6 +9,12 @@ CHANGELOG
* Added `ControllerTrait::isFormValid()`
* Added an `help_html` form option to display the `help` text as HTML
+ * [BC Break] When using Messenger, the default transport changed from
+ using Symfony's serializer service to use `PhpSerializer`, which uses
+ PHP's native `serialize()` and `unserialize()` functions. To use the
+ original serialization method, set the `framework.messenger.serializer.id`
+ config option to `messenger.transport.symfony_serializer`.
+
4.2.0
-----
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index 1a8d6fb461..b1849afde8 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -1060,7 +1060,7 @@ class Configuration implements ConfigurationInterface
})
->end()
->children()
- ->scalarNode('id')->defaultValue(!class_exists(FullStack::class) && class_exists(Serializer::class) ? 'messenger.transport.symfony_serializer' : null)->end()
+ ->scalarNode('id')->defaultValue('messenger.transport.native_php_serializer')->end()
->scalarNode('format')->defaultValue('json')->end()
->arrayNode('context')
->normalizeKeys(false)
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index 679064b8cc..8a1ec7bb5c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -1529,7 +1529,7 @@ class FrameworkExtension extends Extension
} else {
if ('messenger.transport.symfony_serializer' === $config['serializer']['id']) {
if (!$this->isConfigEnabled($container, $serializerConfig)) {
- throw new LogicException('The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".');
+ throw new LogicException('The Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".');
}
$container->getDefinition('messenger.transport.symfony_serializer')
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
index 9d8a0ff74d..92ec3b555e 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
@@ -24,6 +24,8 @@
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
index 453ccf449d..d8acb04909 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
@@ -19,7 +19,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Lock\Store\SemaphoreStore;
use Symfony\Component\Messenger\MessageBusInterface;
-use Symfony\Component\Serializer\Serializer;
class ConfigurationTest extends TestCase
{
@@ -295,7 +294,7 @@ class ConfigurationTest extends TestCase
'routing' => [],
'transports' => [],
'serializer' => [
- 'id' => !class_exists(FullStack::class) && class_exists(Serializer::class) ? 'messenger.transport.symfony_serializer' : null,
+ 'id' => 'messenger.transport.native_php_serializer',
'format' => 'json',
'context' => [],
],
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index 862786c9b8..6d3563d078 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -660,7 +660,7 @@ abstract class FrameworkExtensionTest extends TestCase
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
- * @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".
+ * @expectedExceptionMessage The Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".
*/
public function testMessengerTransportConfigurationWithoutSerializer()
{
diff --git a/src/Symfony/Component/Messenger/CHANGELOG.md b/src/Symfony/Component/Messenger/CHANGELOG.md
index eb1268e25e..ff901be210 100644
--- a/src/Symfony/Component/Messenger/CHANGELOG.md
+++ b/src/Symfony/Component/Messenger/CHANGELOG.md
@@ -1,6 +1,16 @@
CHANGELOG
=========
+4.3.0
+-----
+
+ * Added `PhpSerializer` which uses PHP's native `serialize()` and
+ `unserialize()` to serialize messages to a transport
+
+ * [BC BREAK] If no serializer were passed, the default serializer
+ changed from `Serializer` to `PhpSerializer` inside `AmqpReceiver`,
+ `AmqpSender`, `AmqpTransport` and `AmqpTransportFactory`.
+
4.2.0
-----
diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php
new file mode 100644
index 0000000000..d3f1da25e4
--- /dev/null
+++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php
@@ -0,0 +1,29 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Messenger\Tests\Transport\Serialization;
+
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Messenger\Envelope;
+use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
+use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
+
+class PhpSerializerTest extends TestCase
+{
+ public function testEncodedIsDecodable()
+ {
+ $serializer = new PhpSerializer();
+
+ $envelope = new Envelope(new DummyMessage('Hello'));
+
+ $this->assertEquals($envelope, $serializer->decode($serializer->encode($envelope)));
+ }
+}
diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpReceiver.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpReceiver.php
index 7ed1fae405..fdd81cac54 100644
--- a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpReceiver.php
+++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpReceiver.php
@@ -13,7 +13,7 @@ namespace Symfony\Component\Messenger\Transport\AmqpExt;
use Symfony\Component\Messenger\Transport\AmqpExt\Exception\RejectMessageExceptionInterface;
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
-use Symfony\Component\Messenger\Transport\Serialization\Serializer;
+use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
/**
@@ -32,7 +32,7 @@ class AmqpReceiver implements ReceiverInterface
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->connection = $connection;
- $this->serializer = $serializer ?? Serializer::create();
+ $this->serializer = $serializer ?? new PhpSerializer();
}
/**
diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpSender.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpSender.php
index 88b99ebb06..74ab0dfaa9 100644
--- a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpSender.php
+++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpSender.php
@@ -13,7 +13,7 @@ namespace Symfony\Component\Messenger\Transport\AmqpExt;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Sender\SenderInterface;
-use Symfony\Component\Messenger\Transport\Serialization\Serializer;
+use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
/**
@@ -31,7 +31,7 @@ class AmqpSender implements SenderInterface
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->connection = $connection;
- $this->serializer = $serializer ?? Serializer::create();
+ $this->serializer = $serializer ?? new PhpSerializer();
}
/**
diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php
index 8e27fb90d8..36967c8459 100644
--- a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php
+++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Messenger\Transport\AmqpExt;
use Symfony\Component\Messenger\Envelope;
-use Symfony\Component\Messenger\Transport\Serialization\Serializer;
+use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
@@ -31,7 +31,7 @@ class AmqpTransport implements TransportInterface
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->connection = $connection;
- $this->serializer = $serializer ?? Serializer::create();
+ $this->serializer = $serializer ?? new PhpSerializer();
}
/**
diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransportFactory.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransportFactory.php
index b958726ea5..477aaf1c55 100644
--- a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransportFactory.php
+++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransportFactory.php
@@ -11,7 +11,7 @@
namespace Symfony\Component\Messenger\Transport\AmqpExt;
-use Symfony\Component\Messenger\Transport\Serialization\Serializer;
+use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
@@ -28,7 +28,7 @@ class AmqpTransportFactory implements TransportFactoryInterface
public function __construct(SerializerInterface $serializer = null, bool $debug = false)
{
- $this->serializer = $serializer ?? Serializer::create();
+ $this->serializer = $serializer ?? new PhpSerializer();
$this->debug = $debug;
}
diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php
new file mode 100644
index 0000000000..ec6176c85d
--- /dev/null
+++ b/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php
@@ -0,0 +1,45 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Messenger\Transport\Serialization;
+
+use Symfony\Component\Messenger\Envelope;
+use Symfony\Component\Messenger\Exception\InvalidArgumentException;
+
+/**
+ * @author Ryan Weaver
+ *
+ * @experimental in 4.2
+ */
+class PhpSerializer implements SerializerInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function decode(array $encodedEnvelope): Envelope
+ {
+ if (empty($encodedEnvelope['body'])) {
+ throw new InvalidArgumentException('Encoded envelope should have at least a "body".');
+ }
+
+ return unserialize($encodedEnvelope['body']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function encode(Envelope $envelope): array
+ {
+ return [
+ 'body' => serialize($envelope),
+ ];
+ }
+}