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..9f87bc8f26 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/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/Serialization/PhpSerializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php
new file mode 100644
index 0000000000..955b6f5467
--- /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 Ruyan 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),
+ ];
+ }
+}