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

Commitc4f3677

Browse files
Add stamps to handle trait
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
1 parentd57efd1 commitc4f3677

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

‎src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add`$stamps = []` parameter to`HandleTrait`
8+
49
7.2
510
---
611

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
useSymfony\Component\Messenger\Exception\LogicException;
1515
useSymfony\Component\Messenger\Stamp\HandledStamp;
16+
useSymfony\Component\Messenger\Stamp\StampInterface;
1617

1718
/**
1819
* Leverages a message bus to expect a single, synchronous message handling and return its result.
@@ -29,15 +30,16 @@ trait HandleTrait
2930
* This behavior is useful for both synchronous command & query buses,
3031
* the last one usually returning the handler result.
3132
*
32-
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
33+
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
34+
* @param StampInterface[] $stamps Stamps to be set on the Envelope which are used to control middlewares behaviors
3335
*/
34-
privatefunctionhandle(object$message):mixed
36+
privatefunctionhandle(object$message,array$stamps = []):mixed
3537
{
3638
if (!isset($this->messageBus)) {
3739
thrownewLogicException(\sprintf('You must provide a "%s" instance in the "%s::$messageBus" property, but that property has not been initialized yet.', MessageBusInterface::class,static::class));
3840
}
3941

40-
$envelope =$this->messageBus->dispatch($message);
42+
$envelope =$this->messageBus->dispatch($message,$stamps);
4143
/** @var HandledStamp[] $handledStamps */
4244
$handledStamps =$envelope->all(HandledStamp::class);
4345

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface MessageBusInterface
2323
* Dispatches the given message.
2424
*
2525
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
26-
* @param StampInterface[] $stamps
26+
* @param StampInterface[] $stamps Stamps set on the Envelope which are used to control middlewares behaviors
2727
*
2828
* @throws ExceptionInterface
2929
*/

‎src/Symfony/Component/Messenger/Tests/HandleTraitTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
useSymfony\Component\Messenger\MessageBus;
1919
useSymfony\Component\Messenger\MessageBusInterface;
2020
useSymfony\Component\Messenger\Stamp\HandledStamp;
21+
useSymfony\Component\Messenger\Stamp\StampInterface;
2122
useSymfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2223

2324
class HandleTraitTestextends TestCase
@@ -56,6 +57,20 @@ public function testHandleAcceptsEnvelopes()
5657
$this->assertSame('result',$queryBus->query($envelope));
5758
}
5859

60+
publicfunctiontestHandleWithStamps()
61+
{
62+
$bus =$this->createMock(MessageBus::class);
63+
$queryBus =newTestQueryBus($bus);
64+
$stamp =$this->createMock(StampInterface::class);
65+
66+
$query =newDummyMessage('Hello');
67+
$bus->expects($this->once())->method('dispatch')->with($query, [$stamp])->willReturn(
68+
newEnvelope($query, [newHandledStamp('result','DummyHandler::__invoke')])
69+
);
70+
71+
$queryBus->query($query, [$stamp]);
72+
}
73+
5974
publicfunctiontestHandleThrowsOnNoHandledStamp()
6075
{
6176
$this->expectException(LogicException::class);
@@ -96,8 +111,8 @@ public function __construct(?MessageBusInterface $messageBus)
96111
}
97112
}
98113

99-
publicfunctionquery($query):string
114+
publicfunctionquery($query,array$stamps = []):string
100115
{
101-
return$this->handle($query);
116+
return$this->handle($query,$stamps);
102117
}
103118
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp