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

Commitc17ea71

Browse files
committed
[Messenger] EnvelopeItemInterface::isTransportable(): bool
1 parenta9acb32 commitc17ea71

File tree

7 files changed

+73
-13
lines changed

7 files changed

+73
-13
lines changed

‎src/Symfony/Component/Messenger/Asynchronous/Middleware/SendMessageMiddleware.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useSymfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
1616
useSymfony\Component\Messenger\Envelope;
1717
useSymfony\Component\Messenger\EnvelopeAwareInterface;
18+
useSymfony\Component\Messenger\EnvelopeItemInterface;
1819
useSymfony\Component\Messenger\Middleware\MiddlewareInterface;
1920

2021
/**
@@ -40,6 +41,10 @@ public function handle($message, callable $next)
4041
return$next($message);
4142
}
4243

44+
$envelope =newEnvelope($envelope->getMessage(),array_filter($envelope->all(),function (EnvelopeItemInterface$item):bool {
45+
return$item->isTransportable();
46+
}));
47+
4348
if (!empty($senders =$this->senderLocator->getSendersForMessage($envelope->getMessage()))) {
4449
foreach ($sendersas$sender) {
4550
if (null ===$sender) {

‎src/Symfony/Component/Messenger/Asynchronous/Transport/ReceivedMessage.php‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
*/
2626
finalclass ReceivedMessageimplements EnvelopeItemInterface
2727
{
28-
publicfunctionserialize()
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
publicfunctionisTransportable():bool
2932
{
30-
return'';
31-
}
32-
33-
publicfunctionunserialize($serialized)
34-
{
35-
// noop
33+
returnfalse;
3634
}
3735
}

‎src/Symfony/Component/Messenger/EnvelopeItemInterface.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313

1414
/**
1515
* An envelope item related to a message.
16-
* This item must be serializable for transport.
1716
*
1817
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
1918
*
2019
* @experimental in 4.1
2120
*/
22-
interface EnvelopeItemInterfaceextends \Serializable
21+
interface EnvelopeItemInterface
2322
{
23+
/**
24+
* @return bool True if this item can be transported. Otherwise, it'll be ignored during send.
25+
*/
26+
publicfunctionisTransportable():bool;
2427
}

‎src/Symfony/Component/Messenger/Middleware/Configuration/ValidationConfiguration.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @experimental in 4.1
2121
*/
22-
finalclass ValidationConfigurationimplements EnvelopeItemInterface
22+
finalclass ValidationConfigurationimplements EnvelopeItemInterface, \Serializable
2323
{
2424
private$groups;
2525

@@ -36,6 +36,14 @@ public function getGroups()
3636
return$this->groups;
3737
}
3838

39+
/**
40+
* {@inheritdoc}
41+
*/
42+
publicfunctionisTransportable():bool
43+
{
44+
returntrue;
45+
}
46+
3947
publicfunctionserialize()
4048
{
4149
$isGroupSequence =$this->groupsinstanceof GroupSequence;

‎src/Symfony/Component/Messenger/Tests/Asynchronous/Middleware/SendMessageMiddlewareTest.php‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\Messenger\Asynchronous\Routing\SenderLocatorInterface;
1717
useSymfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
1818
useSymfony\Component\Messenger\Envelope;
19+
useSymfony\Component\Messenger\EnvelopeItemInterface;
1920
useSymfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2021
useSymfony\Component\Messenger\Transport\SenderInterface;
2122

@@ -37,6 +38,27 @@ public function testItSendsTheMessageToAssignedSender()
3738
$middleware->handle($message,$next);
3839
}
3940

41+
publicfunctiontestItSendsEnvelopeWithTransportableItemsOnly()
42+
{
43+
$envelope = Envelope::wrap(newDummyMessage('Hey'))
44+
->with(newTransportableItem())
45+
->with(newNonTransportableItem())
46+
;
47+
$sender =$this->getMockBuilder(SenderInterface::class)->getMock();
48+
$next =$this->createPartialMock(\stdClass::class,array('__invoke'));
49+
50+
$middleware =newSendMessageMiddleware(newInMemorySenderLocator(array(
51+
$sender,
52+
)));
53+
54+
$sender->expects($this->once())->method('send')->with(Envelope::wrap(newDummyMessage('Hey'))
55+
->with(newTransportableItem())
56+
);
57+
$next->expects($this->never())->method($this->anything());
58+
59+
$middleware->handle($envelope,$next);
60+
}
61+
4062
publicfunctiontestItSendsTheMessageToAssignedSenderWithPreWrappedMessage()
4163
{
4264
$envelope = Envelope::wrap(newDummyMessage('Hey'));
@@ -114,3 +136,19 @@ public function getSendersForMessage($message): array
114136
return$this->senders;
115137
}
116138
}
139+
140+
class TransportableItemimplements EnvelopeItemInterface
141+
{
142+
publicfunctionisTransportable():bool
143+
{
144+
returntrue;
145+
}
146+
}
147+
148+
class NonTransportableItemimplements EnvelopeItemInterface
149+
{
150+
publicfunctionisTransportable():bool
151+
{
152+
returnfalse;
153+
}
154+
}

‎src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function encode(Envelope $envelope): array
6868
}
6969

7070
$headers =array('type' =>\get_class($envelope->getMessage()));
71-
if ($configurations =$envelope->all()) {
72-
$headers['X-Message-Envelope-Items'] =serialize($configurations);
71+
if ($items =$envelope->all()) {
72+
$headers['X-Message-Envelope-Items'] =serialize($items);
7373
}
7474

7575
returnarray(

‎src/Symfony/Component/Messenger/Transport/Serialization/SerializerConfiguration.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @experimental in 4.1
2020
*/
21-
finalclass SerializerConfigurationimplements EnvelopeItemInterface
21+
finalclass SerializerConfigurationimplements EnvelopeItemInterface, \Serializable
2222
{
2323
private$context;
2424

@@ -32,6 +32,14 @@ public function getContext(): array
3232
return$this->context;
3333
}
3434

35+
/**
36+
* {@inheritdoc}
37+
*/
38+
publicfunctionisTransportable():bool
39+
{
40+
returntrue;
41+
}
42+
3543
publicfunctionserialize()
3644
{
3745
returnserialize(array('context' =>$this->context));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp