Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb4788e4

Browse files
committed
introducing native php serialize() support for Messenger transport
1 parenta9f8ca5 commitb4788e4

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ function ($a) {
10601060
})
10611061
->end()
10621062
->children()
1063-
->scalarNode('id')->defaultValue(!class_exists(FullStack::class) &&class_exists(Serializer::class) ?'messenger.transport.symfony_serializer' :null)->end()
1063+
->scalarNode('id')->defaultValue('messenger.transport.native_php_serializer')->end()
10641064
->scalarNode('format')->defaultValue('json')->end()
10651065
->arrayNode('context')
10661066
->normalizeKeys(false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
15291529
}else {
15301530
if ('messenger.transport.symfony_serializer' ===$config['serializer']['id']) {
15311531
if (!$this->isConfigEnabled($container,$serializerConfig)) {
1532-
thrownewLogicException('ThedefaultMessenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".');
1532+
thrownewLogicException('The Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".');
15331533
}
15341534

15351535
$container->getDefinition('messenger.transport.symfony_serializer')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</service>
2525
<serviceid="Symfony\Component\Messenger\Transport\Serialization\SerializerInterface"alias="messenger.transport.serializer" />
2626

27+
<serviceid="messenger.transport.native_php_serializer"class="Symfony\Component\Messenger\Transport\Serialization\Serializer" />
28+
2729
<!-- Middleware-->
2830
<serviceid="messenger.middleware.handle_message"class="Symfony\Component\Messenger\Middleware\HandleMessageMiddleware"abstract="true">
2931
<argument /><!-- Bus handler resolver-->
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
namespaceSymfony\Component\Messenger\Tests\Transport\Serialization;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Messenger\Envelope;
16+
useSymfony\Component\Messenger\Tests\Fixtures\DummyMessage;
17+
useSymfony\Component\Messenger\Transport\Serialization\PhpSerializer;
18+
19+
class PhpSerializerTestextends TestCase
20+
{
21+
publicfunctiontestEncodedIsDecodable()
22+
{
23+
$serializer =newPhpSerializer();
24+
25+
$envelope =newEnvelope(newDummyMessage('Hello'));
26+
27+
$this->assertEquals($envelope,$serializer->decode($serializer->encode($envelope)));
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
namespaceSymfony\Component\Messenger\Transport\Serialization;
13+
14+
useSymfony\Component\Messenger\Envelope;
15+
useSymfony\Component\Messenger\Exception\InvalidArgumentException;
16+
17+
/**
18+
* @author Ruyan Weaver<ryan@symfonycasts.com>
19+
*
20+
* @experimental in 4.2
21+
*/
22+
class PhpSerializerimplements SerializerInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
publicfunctiondecode(array$encodedEnvelope):Envelope
28+
{
29+
if (empty($encodedEnvelope['body'])) {
30+
thrownewInvalidArgumentException('Encoded envelope should have at least a "body".');
31+
}
32+
33+
returnunserialize($encodedEnvelope['body']);
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
publicfunctionencode(Envelope$envelope):array
40+
{
41+
return [
42+
'body' =>serialize($envelope),
43+
];
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp