Skip to content

[Messenger] rename "envelope items" and move them in the "Stamp" namespace #28911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
}
Expand Down

This file was deleted.

21 changes: 13 additions & 8 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 18 additions & 14 deletions src/Symfony/Component/Messenger/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,6 +23,6 @@
*
* @author Samuel Roze <samuel.roze@gmail.com>
*/
final class ReceivedMessage implements EnvelopeItemInterface
final class ReceivedStamp implements StampInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading