Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44d2ce4

Browse filesBrowse files
committed
introducing native php serialize() support for Messenger transport
1 parent 7377265 commit 44d2ce4
Copy full SHA for 44d2ce4

File tree

4 files changed

+90
-1
lines changed
Filter options

4 files changed

+90
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ function ($a) {
10461046
})
10471047
->end()
10481048
->children()
1049-
->scalarNode('id')->defaultValue('messenger.transport.symfony_serializer')->end()
1049+
->scalarNode('id')->defaultValue('messenger.transport.native_php_serializer')->end()
10501050
->scalarNode('format')->defaultValue('json')->end()
10511051
->arrayNode('context')
10521052
->normalizeKeys(false)

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<argument type="collection" /> <!-- Context -->
2424
</service>
2525

26+
<service id="messenger.transport.native_php_serializer" class="Symfony\Component\Messenger\Transport\Serialization\Serializer" />
27+
2628
<!-- Middleware -->
2729
<service id="messenger.middleware.handle_message" class="Symfony\Component\Messenger\Middleware\HandleMessageMiddleware" abstract="true">
2830
<argument /> <!-- Bus handler resolver -->
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Transport\Serialization;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Messenger\Envelope;
16+
use Symfony\Component\Messenger\Stamp\SerializerStamp;
17+
use Symfony\Component\Messenger\Stamp\ValidationStamp;
18+
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
19+
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
20+
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
21+
use Symfony\Component\Serializer as SerializerComponent;
22+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
23+
24+
class PhpSerializerTest extends TestCase
25+
{
26+
public function testEncodedIsDecodable()
27+
{
28+
$serializer = new PhpSerializer();
29+
30+
$envelope = new Envelope(new DummyMessage('Hello'));
31+
32+
$this->assertEquals($envelope, $serializer->decode($serializer->encode($envelope)));
33+
}
34+
}
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Transport\Serialization;
13+
14+
use Symfony\Component\Messenger\Envelope;
15+
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
16+
use Symfony\Component\Messenger\Exception\LogicException;
17+
use Symfony\Component\Messenger\Stamp\SerializerStamp;
18+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
19+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
20+
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
21+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
22+
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
23+
use Symfony\Component\Serializer\SerializerInterface as SymfonySerializerInterface;
24+
25+
/**
26+
* @author Ruyan Weaver<ryan@symfonycasts.com>
27+
*
28+
* @experimental in 4.2
29+
*/
30+
class PhpSerializer implements SerializerInterface
31+
{
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function decode(array $encodedEnvelope): Envelope
36+
{
37+
if (empty($encodedEnvelope['body'])) {
38+
throw new InvalidArgumentException('Encoded envelope should have at least a "body".');
39+
}
40+
41+
return unserialize($encodedEnvelope['body']);
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function encode(Envelope $envelope): array
48+
{
49+
return array(
50+
'body' => serialize($envelope),
51+
);
52+
}
53+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.