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 9d69f84

Browse filesBrowse files
Add stamps to handle trait
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
1 parent 3d4e0d6 commit 9d69f84
Copy full SHA for 9d69f84

File tree

4 files changed

+24
-6
lines changed
Filter options

4 files changed

+24
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add `CloseableTransportInterface` to allow closing the transport
88
* Add `SentForRetryStamp` that identifies whether a failed message was sent for retry
99
* Add `Symfony\Component\Messenger\Middleware\DeduplicateMiddleware` and `Symfony\Component\Messenger\Stamp\DeduplicateStamp`
10+
* Add `$stamps = []` parameter to `HandleTrait`
1011

1112
7.2
1213
---

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/HandleTrait.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Messenger\Exception\LogicException;
1515
use Symfony\Component\Messenger\Stamp\HandledStamp;
16+
use Symfony\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-
private function handle(object $message): mixed
36+
private function handle(object $message, array $stamps = []): mixed
3537
{
3638
if (!isset($this->messageBus)) {
3739
throw new LogicException(\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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/MessageBusInterface.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/HandleTraitTest.php
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Messenger\MessageBus;
1919
use Symfony\Component\Messenger\MessageBusInterface;
2020
use Symfony\Component\Messenger\Stamp\HandledStamp;
21+
use Symfony\Component\Messenger\Stamp\StampInterface;
2122
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2223

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

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

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

0 commit comments

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