8000 feature #28911 [Messenger] rename "envelope items" and move them in t… · symfony/symfony@4d757b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d757b5

Browse files
feature #28911 [Messenger] rename "envelope items" and move them in the "Stamp" namespace (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Messenger] rename "envelope items" and move them in the "Stamp" namespace | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Right now, envelope items are scattered in different sub namespaces and use the "Configuration" suffix. This makes them hard to discover. This PR creates a new `Stamp` namespace and moves all "envelope items" there, renaming them to use the "stamp" terminology. From the changelog: * `Envelope`'s constructor and `with` method now accept `StampInterface` objects as variadic parameters * Renamed `EnvelopeItemInterface` to `StampInterface` * Renamed and moved `ReceivedMessage`, `ValidationConfiguration` and `SerializerConfiguration` in the `Stamp` namespace * Removed the `WrapIntoReceivedMessage` (it's untested and unused) Commits ------- 0ad2cb9 [Messenger] rename "envelope items" and move them in the "Stamp" namespace
2 parents 0acf9e1 + 0ad2cb9 commit 4d757b5

29 files changed

+179
-224
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/messenger.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@
159159
<td>{{ profiler_dump(dispatchCall.message.value, maxDepth=2) }}</td>
160160
</tr>
161161
<tr>
162-
<td class="text-bold">Envelope items</td>
162+
<td class="text-bold">Envelope stamps</td>
163163
<td>
164-
{% for item in dispatchCall.envelopeItems %}
164+
{% for item in dispatchCall.stamps %}
165165
{{ profiler_dump(item) }}
166166
{% else %}
167167
<span class="text-muted">No items</span>

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

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

1414
use Symfony\Component\Messenger\Asynchronous\Routing\AbstractSenderLocator;
1515
use Symfony\Component\Messenger\Asynchronous\Routing\SenderLocatorInterface;
16-
use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
1716
use Symfony\Component\Messenger\Envelope;
1817
use Symfony\Component\Messenger\EnvelopeAwareInterface;
1918
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
19+
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
2020

2121
/**
2222
* @author Samuel Roze <samuel.roze@gmail.com>
@@ -40,7 +40,7 @@ public function __construct(SenderLocatorInterface $senderLocator, array $messag
4040
*/
4141
public function handle($envelope, callable $next)
4242
{
43-
if ($envelope->get(ReceivedMessage::class)) {
43+
if ($envelope->get(ReceivedStamp::class)) {
4444
// It's a received message. Do not send it back:
4545
return $next($envelope);
4646
}

src/Symfony/Component/Messenger/Asynchronous/Transport/WrapIntoReceivedMessage.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ CHANGELOG
55
-----
66

77
* The component is not experimental anymore
8-
* [BC BREAK] The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
8+
* All the changes below are BC BREAKS
9+
* The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
910
`Serializer` as a second argument.
10-
* [BC BREAK] `SenderLocator` has been renamed to `ContainerSenderLocator`
11+
* `SenderLocator` has been renamed to `ContainerSenderLocator`
1112
Be careful as there is still a `SenderLocator` class, but it does not rely on a `ContainerInterface` to find senders.
1213
Instead, it accepts the sender instance itself instead of its identifier in the container.
13-
* [BC BREAK] `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
14+
* `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
1415
needs to be an associative array or the method name.
1516
* `ValidationMiddleware::handle()` and `SendMessageMiddleware::handle()` now require an `Envelope` object
16-
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
17-
* [BC BREAK] The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface`
17+
* `StampInterface` replaces `EnvelopeItemInterface` and doesn't extend `Serializable` anymore
18+
* The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface`
1819
as first constructor argument
19-
* [BC BREAK] The `EncoderInterface` and `DecoderInterface` have been replaced by a unified `Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`.
20-
* [BC BREAK] The locator passed to `ContainerHandlerLocator` should not prefix its keys by "handler." anymore
21-
* [BC BREAK] The `AbstractHandlerLocator::getHandler()` method uses `?callable` as return type
20+
* The `EncoderInterface` and `DecoderInterface` have been replaced by a unified `Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`.
21+
* The locator passed to `ContainerHandlerLocator` should not prefix its keys by "handler." anymore
22+
* The `AbstractHandlerLocator::getHandler()` method uses `?callable` as return type
23+
* Renamed `EnvelopeItemInterface` to `StampInterface`
24+
* `Envelope`'s constructor and `with()` method now accept `StampInterface` objects as variadic parameters
25+
* Renamed and moved `ReceivedMessage`, `ValidationConfiguration` and `SerializerConfiguration` in the `Stamp` namespace
26+
* Removed the `WrapIntoReceivedMessage`
2227

2328
4.1.0
2429
-----

src/Symfony/Component/Messenger/DataCollector/MessengerDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function collectMessage(string $busName, array $tracedMessage)
9090

9191
$debugRepresentation = array(
9292
'bus' => $busName,
93-
'envelopeItems' => $tracedMessage['envelopeItems'] ?? null,
93+
'stamps' => $tracedMessage['stamps'] ?? null,
9494
'message' => array(
9595
'type' => new ClassStub(\get_class($message)),
9696
'value' => $message,

src/Symfony/Component/Messenger/Envelope.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@
1111

1212
namespace Symfony\Component\Messenger;
1313

14+
use Symfony\Component\Messenger\Stamp\StampInterface;
15+
1416
/**
15-
* A message wrapped in an envelope with items (configurations, markers, ...).
17+
* A message wrapped in an envelope with stamps (configurations, markers, ...).
1618
*
1719
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
1820
*/
1921
final class Envelope
2022
{
21-
private $items = array();
23+
private $stamps = array();
2224
private $message;
2325

2426
/**
25-
* @param object $message
26-
* @param EnvelopeItemInterface[] $items
27+
* @param object $message
2728
*/
28-
public function __construct($message, array $items = array())
29+
public function __construct($message< 1CF5 /span>, StampInterface ...$stamps)
2930
{
3031
$this->message = $message;
31-
foreach ($items as $item) {
32-
$this->items[\get_class($item)] = $item;
32+
33+
foreach ($stamps as $stamp) {
34+
$this->stamps[\get_class($stamp)] = $stamp;
3335
}
3436
}
3537

@@ -44,13 +46,15 @@ public static function wrap($message): self
4446
}
4547

4648
/**
47-
* @return Envelope a new Envelope instance with additional item
49+
* @return Envelope a new Envelope instance with additional stamp
4850
*/
49-
public function with(EnvelopeItemInterface $item): self
51+
public function with(StampInterface ...$stamps): self
5052
{
5153
$cloned = clone $this;
5254

53-
$cloned->items[\get_class($item)] = $item;
55+
foreach ($stamps as $stamp) {
56+
$cloned->stamps[\get_class($stamp)] = $stamp;
57+
}
5458

5559
return $cloned;
5660
}
@@ -64,17 +68,17 @@ public function withMessage($message): self
6468
return $cloned;
6569
}
6670

67-
public function get(string $itemFqcn): ?EnvelopeItemInterface
71+
public function get(string $stampFqcn): ?StampInterface
6872
{
69-
return $this->items[$itemFqcn] ?? null;
73+
return $this->stamps[$stampFqcn] ?? null;
7074
}
7175

7276
/**
73-
* @return EnvelopeItemInterface[] indexed by fqcn
77+
* @return StampInterface[] indexed by fqcn
7478
*/
7579
public function all(): array
7680
{
77-
return $this->items;
81+
return $this->stamps;
7882
}
7983

8084
/**

src/Symfony/Component/Messenger/Middleware/ValidationMiddleware.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Messenger\Envelope;
1515
use Symfony\Component\Messenger\EnvelopeAwareInterface;
1616
use Symfony\Component\Messenger\Exception\ValidationFailedException;
17-
use Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration;
17+
use Symfony\Component\Messenger\Stamp\ValidationStamp;
1818
use Symfony\Component\Validator\Validator\ValidatorInterface;
1919

2020
/**
@@ -36,9 +36,9 @@ public function handle($envelope, callable $next)
3636
{
3737
$message = $envelope->getMessage();
3838
$groups = null;
39-
/** @var ValidationConfiguration|null $validationConfig */
40-
if ($validationConfig = $envelope->get(ValidationConfiguration::class)) {
41-
$groups = $validationConfig->getGroups();
39+
/** @var ValidationStamp|null $validationStamp */
40+
if ($validationStamp = $envelope->get(ValidationStamp::class)) {
41+
$groups = $validationStamp->getGroups();
4242
}
4343

4444
$violations = $this->validator->validate($message, null, $groups);

src/Symfony/Component/Messenger/Asynchronous/Transport/ReceivedMessage.php renamed to src/Symfony/Component/Messenger/Stamp/ReceivedStamp.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Messenger\Asynchronous\Transport;
12+
namespace Symfony\Component\Messenger\Stamp;
1313

1414
use Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware;
15-
use Symfony\Component\Messenger\EnvelopeItemInterface;
1615

1716
/**
1817
* Marker config for a received message.
@@ -24,6 +23,6 @@
2423
*
2524
* @author Samuel Roze <samuel.roze@gmail.com>
2625
*/
27-
final class ReceivedMessage implements EnvelopeItemInterface
26+
final class ReceivedStamp implements StampInterface
2827
{
2928
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Messenger\Transport\Serialization;
13-
14-
use Symfony\Component\Messenger\EnvelopeItemInterface;
12+
namespace Symfony\Component\Messenger\Stamp;
1513

1614
/**
1715
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
1816
*/
19-
final class SerializerConfiguration implements EnvelopeItemInterface
17+
final class SerializerStamp implements StampInterface
2018
{
2119
private $context;
2220

src/Symfony/Component/Messenger/EnvelopeItemInterface.php renamed to src/Symfony/Component/Messenger/Stamp/StampInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Messenger;
12+
namespace Symfony\Component\Messenger\Stamp;
1313

1414
/**
15-
* An envelope item related to a message.
15+
* An envelope stamp related to a message.
1616
*
17-
* This item must be serializable for transport.
17+
* Stamps must be serializable value objects for transport.
1818
*
1919
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
2020
*/
21-
interface EnvelopeItemInterface
21+
interface StampInterface
2222
{
2323
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Messenger\Middleware\Configuration;
12+
namespace Symfony\Component\Messenger\Stamp;
1313

14-
use Symfony\Component\Messenger\EnvelopeItemInterface;
1514
use Symfony\Component\Validator\Constraints\GroupSequence;
1615

1716
/**
1817
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
1918
*/
20-
final class ValidationConfiguration implements EnvelopeItemInterface
19+
final class ValidationStamp implements StampInterface
2120
{
2221
private $groups;
2322

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware;
1616
use Symfony\Component\Messenger\Asynchronous\Routing\SenderLocatorInterface;
17-
use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
1817
use Symfony\Component\Messenger\Envelope;
18+
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
1919
use Symfony\Component\Messenger\Tests\Fixtures\ChildDummyMessage;
2020
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2121
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessageInterface;
@@ -135,7 +135,7 @@ public function testItCallsTheNextMiddlewareWhenNoSenderForThisMessage()
135135

136136
public function testItSkipsReceivedMessages()
137137
{
138-
$envelope = Envelope::wrap(new DummyMessage('Hey'))->with(new ReceivedMessage());
138+
$envelope = Envelope::wrap(new DummyMessage('Hey'))->with(new ReceivedStamp());
139139

140140
$sender = $this->getMockBuilder(SenderInterface::class)->getMock();
141141
$next = $this->createPartialMock(\stdClass::class, array('__invoke'));

src/Symfony/Component/Messenger/Tests/DataCollector/MessengerDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getHandleTestData()
6262
$file = __FILE__;
6363
$messageDump = <<<DUMP
6464
"bus" => "default"
65-
"envelopeItems" => null
65+
"stamps" => null
6666
"message" => array:2 [
6767
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
6868
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A
@@ -145,7 +145,7 @@ public function testHandleWithException()
145145
$this->assertStringMatchesFormat(<<<DUMP
146146
array:5 [
147147
"bus" => "default"
148-
"envelopeItems" => null
148+
"stamps" => null
149149
"message" => array:2 [
150150
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
151151
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A

0 commit comments

Comments
 (0)
0