Permalink
Browse files

feature #28911 [Messenger] rename "envelope items" and move them in t…

…he "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
  • Loading branch information...
nicolas-grekas committed Oct 20, 2018
2 parents 0acf9e1 + 0ad2cb9 commit 4d757b5382e1356c96cf666392b301708bf97c38
Showing with 179 additions and 224 deletions.
  1. +2 −2 src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/messenger.html.twig
  2. +2 −2 src/Symfony/Component/Messenger/Asynchronous/Middleware/SendMessageMiddleware.php
  3. +0 −44 src/Symfony/Component/Messenger/Asynchronous/Transport/WrapIntoReceivedMessage.php
  4. +13 −8 src/Symfony/Component/Messenger/CHANGELOG.md
  5. +1 −1 src/Symfony/Component/Messenger/DataCollector/MessengerDataCollector.php
  6. +18 −14 src/Symfony/Component/Messenger/Envelope.php
  7. +4 −4 src/Symfony/Component/Messenger/Middleware/ValidationMiddleware.php
  8. +2 −3 ...ymfony/Component/Messenger/{Asynchronous/Transport/ReceivedMessage.php → Stamp/ReceivedStamp.php}
  9. +2 −4 ...onent/Messenger/{Transport/Serialization/SerializerConfiguration.php → Stamp/SerializerStamp.php}
  10. +4 −4 src/Symfony/Component/Messenger/{EnvelopeItemInterface.php → Stamp/StampInterface.php}
  11. +2 −3 ...nent/Messenger/{Middleware/Configuration/ValidationConfiguration.php → Stamp/ValidationStamp.php}
  12. +2 −2 src/Symfony/Component/Messenger/Tests/Asynchronous/Middleware/SendMessageMiddlewareTest.php
  13. +2 −2 src/Symfony/Component/Messenger/Tests/DataCollector/MessengerDataCollectorTest.php
  14. +18 −25 src/Symfony/Component/Messenger/Tests/EnvelopeTest.php
  15. +2 −2 src/Symfony/Component/Messenger/Tests/Fixtures/{AnEnvelopeItem.php → AnEnvelopeStamp.php}
  16. +11 −11 src/Symfony/Component/Messenger/Tests/MessageBusTest.php
  17. +0 −37 src/Symfony/Component/Messenger/Tests/Middleware/Configuration/ValidationConfigurationTest.php
  18. +3 −3 src/Symfony/Component/Messenger/Tests/Middleware/ValidationMiddlewareTest.php
  19. +4 −4 ...chronous/Transport/Serialization/SerializerConfigurationTest.php → Stamp/SerializerStampTest.php}
  20. +37 −0 src/Symfony/Component/Messenger/Tests/Stamp/ValidationStampTest.php
  21. +5 −5 src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php
  22. +2 −2 src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/AmqpExtIntegrationTest.php
  23. +1 −1 src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/Fixtures/long_receiver.php
  24. +12 −13 src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php
  25. +4 −4 src/Symfony/Component/Messenger/Tests/WorkerTest.php
  26. +3 −3 src/Symfony/Component/Messenger/TraceableMessageBus.php
  27. +20 −18 src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php
  28. +1 −1 src/Symfony/Component/Messenger/Transport/Serialization/SerializerInterface.php
  29. +2 −2 src/Symfony/Component/Messenger/Worker.php
@@ -159,9 +159,9 @@
<td>{{ profiler_dump(dispatchCall.message.value, maxDepth=2) }}</td>
</tr>
<tr>
<td class="text-bold">Envelope items</td>
<td class="text-bold">Envelope stamps</td>
<td>
{% for item in dispatchCall.envelopeItems %}
{% for item in dispatchCall.stamps %}
{{ profiler_dump(item) }}
{% else %}
<span class="text-muted">No items</span>
@@ -13,10 +13,10 @@
use Symfony\Component\Messenger\Asynchronous\Routing\AbstractSenderLocator;
use Symfony\Component\Messenger\Asynchronous\Routing\SenderLocatorInterface;
use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\EnvelopeAwareInterface;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
@@ -40,7 +40,7 @@ public function __construct(SenderLocatorInterface $senderLocator, array $messag
*/
public function handle($envelope, callable $next)
{
if ($envelope->get(ReceivedMessage::class)) {
if ($envelope->get(ReceivedStamp::class)) {
// It's a received message. Do not send it back:
return $next($envelope);
}

This file was deleted.

Oops, something went wrong.
@@ -5,20 +5,25 @@ CHANGELOG
-----
* The component is not experimental anymore
* [BC BREAK] The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
* All the changes below are BC BREAKS
* The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
`Serializer` as a second argument.
* [BC BREAK] `SenderLocator` has been renamed to `ContainerSenderLocator`
* `SenderLocator` has been renamed to `ContainerSenderLocator`
Be careful as there is still a `SenderLocator` class, but it does not rely on a `ContainerInterface` to find senders.
Instead, it accepts the sender instance itself instead of its identifier in the container.
* [BC BREAK] `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
* `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
needs to be an associative array or the method name.
* `ValidationMiddleware::handle()` and `SendMessageMiddleware::handle()` now require an `Envelope` object
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
* [BC BREAK] The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface`
* `StampInterface` replaces `EnvelopeItemInterface` and doesn't extend `Serializable` anymore
* The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface`
as first constructor argument
* [BC BREAK] The `EncoderInterface` and `DecoderInterface` have been replaced by a unified `Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`.
* [BC BREAK] The locator passed to `ContainerHandlerLocator` should not prefix its keys by "handler." anymore
* [BC BREAK] The `AbstractHandlerLocator::getHandler()` method uses `?callable` as return type
* The `EncoderInterface` and `DecoderInterface` have been replaced by a unified `Symfony\Component\Messenger\Transport\Serialization\SerializerInterface`.
* The locator passed to `ContainerHandlerLocator` should not prefix its keys by "handler." anymore
* The `AbstractHandlerLocator::getHandler()` method uses `?callable` as return type
* Renamed `EnvelopeItemInterface` to `StampInterface`
* `Envelope`'s constructor and `with()` method now accept `StampInterface` objects as variadic parameters
* Renamed and moved `ReceivedMessage`, `ValidationConfiguration` and `SerializerConfiguration` in the `Stamp` namespace
* Removed the `WrapIntoReceivedMessage`
4.1.0
-----
@@ -90,7 +90,7 @@ private function collectMessage(string $busName, array $tracedMessage)
$debugRepresentation = array(
'bus' => $busName,
'envelopeItems' => $tracedMessage['envelopeItems'] ?? null,
'stamps' => $tracedMessage['stamps'] ?? null,
'message' => array(
'type' => new ClassStub(\get_class($message)),
'value' => $message,
@@ -11,25 +11,27 @@
namespace Symfony\Component\Messenger;
use Symfony\Component\Messenger\Stamp\StampInterface;
/**
* A message wrapped in an envelope with items (configurations, markers, ...).
* A message wrapped in an envelope with stamps (configurations, markers, ...).
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
final class Envelope
{
private $items = array();
private $stamps = array();
private $message;
/**
* @param object $message
* @param EnvelopeItemInterface[] $items
* @param object $message
*/
public function __construct($message, array $items = array())
public function __construct($message, StampInterface ...$stamps)
{
$this->message = $message;
foreach ($items as $item) {
$this->items[\get_class($item)] = $item;
foreach ($stamps as $stamp) {
$this->stamps[\get_class($stamp)] = $stamp;
}
}
@@ -44,13 +46,15 @@ public static function wrap($message): self
}
/**
* @return Envelope a new Envelope instance with additional item
* @return Envelope a new Envelope instance with additional stamp
*/
public function with(EnvelopeItemInterface $item): self
public function with(StampInterface ...$stamps): self
{
$cloned = clone $this;
$cloned->items[\get_class($item)] = $item;
foreach ($stamps as $stamp) {
$cloned->stamps[\get_class($stamp)] = $stamp;
}
return $cloned;
}
@@ -64,17 +68,17 @@ public function withMessage($message): self
return $cloned;
}
public function get(string $itemFqcn): ?EnvelopeItemInterface
public function get(string $stampFqcn): ?StampInterface
{
return $this->items[$itemFqcn] ?? null;
return $this->stamps[$stampFqcn] ?? null;
}
/**
* @return EnvelopeItemInterface[] indexed by fqcn
* @return StampInterface[] indexed by fqcn
*/
public function all(): array
{
return $this->items;
return $this->stamps;
}
/**
@@ -14,7 +14,7 @@
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\EnvelopeAwareInterface;
use Symfony\Component\Messenger\Exception\ValidationFailedException;
use Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration;
use Symfony\Component\Messenger\Stamp\ValidationStamp;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
@@ -36,9 +36,9 @@ public function handle($envelope, callable $next)
{
$message = $envelope->getMessage();
$groups = null;
/** @var ValidationConfiguration|null $validationConfig */
if ($validationConfig = $envelope->get(ValidationConfiguration::class)) {
$groups = $validationConfig->getGroups();
/** @var ValidationStamp|null $validationStamp */
if ($validationStamp = $envelope->get(ValidationStamp::class)) {
$groups = $validationStamp->getGroups();
}
$violations = $this->validator->validate($message, null, $groups);
@@ -9,10 +9,9 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Asynchronous\Transport;
namespace Symfony\Component\Messenger\Stamp;
use Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware;
use Symfony\Component\Messenger\EnvelopeItemInterface;
/**
* Marker config for a received message.
@@ -24,6 +23,6 @@
*
* @author Samuel Roze <samuel.roze@gmail.com>
*/
final class ReceivedMessage implements EnvelopeItemInterface
final class ReceivedStamp implements StampInterface
{
}
@@ -9,14 +9,12 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Transport\Serialization;
use Symfony\Component\Messenger\EnvelopeItemInterface;
namespace Symfony\Component\Messenger\Stamp;
/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
final class SerializerConfiguration implements EnvelopeItemInterface
final class SerializerStamp implements StampInterface
{
private $context;
@@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger;
namespace Symfony\Component\Messenger\Stamp;
/**
* An envelope item related to a message.
* An envelope stamp related to a message.
*
* This item must be serializable for transport.
* Stamps must be serializable value objects for transport.
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
interface EnvelopeItemInterface
interface StampInterface
{
}
@@ -9,15 +9,14 @@
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Middleware\Configuration;
namespace Symfony\Component\Messenger\Stamp;
use Symfony\Component\Messenger\EnvelopeItemInterface;
use Symfony\Component\Validator\Constraints\GroupSequence;
/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
final class ValidationConfiguration implements EnvelopeItemInterface
final class ValidationStamp implements StampInterface
{
private $groups;
@@ -14,8 +14,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware;
use Symfony\Component\Messenger\Asynchronous\Routing\SenderLocatorInterface;
use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
use Symfony\Component\Messenger\Tests\Fixtures\ChildDummyMessage;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessageInterface;
@@ -135,7 +135,7 @@ public function testItCallsTheNextMiddlewareWhenNoSenderForThisMessage()
public function testItSkipsReceivedMessages()
{
$envelope = Envelope::wrap(new DummyMessage('Hey'))->with(new ReceivedMessage());
$envelope = Envelope::wrap(new DummyMessage('Hey'))->with(new ReceivedStamp());
$sender = $this->getMockBuilder(SenderInterface::class)->getMock();
$next = $this->createPartialMock(\stdClass::class, array('__invoke'));
@@ -62,7 +62,7 @@ public function getHandleTestData()
$file = __FILE__;
$messageDump = <<<DUMP
"bus" => "default"
"envelopeItems" => null
"stamps" => null
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A
@@ -145,7 +145,7 @@ public function testHandleWithException()
$this->assertStringMatchesFormat(<<<DUMP
array:5 [
"bus" => "default"
"envelopeItems" => null
"stamps" => null
"message" => array:2 [
"type" => "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage"
"value" => Symfony\Component\Messenger\Tests\Fixtures\DummyMessage %A
Oops, something went wrong.

0 comments on commit 4d757b5

Please sign in to comment.