8000 [Messenger] Don't make EnvelopeItemInterface extend Serializable by nicolas-grekas · Pull Request #28247 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Don't make EnvelopeItemInterface extend Serializable #28247

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
Aug 27, 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
1 change: 1 addition & 0 deletions UPGRADE-4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ FrameworkBundle
Messenger
---------

* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
* The `handle` method of the `Symfony\Component\Messenger\Middleware\ValidationMiddleware` and `Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware` middlewares now requires an `Envelope` object to be given (because they implement the `EnvelopeAwareInterface`). When using these middleware with the provided `MessageBus`, you will not have to do anything. If you use the middlewares any other way, you can use `Envelope::wrap($message)` to create an envelope for your message.

Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* Marker config for a received message.
*
* This is mainly used by the `SendMessageMiddleware` middleware to identify
* a message should not be sent if it was just received.
*
Expand All @@ -25,13 +26,4 @@
*/
final class ReceivedMessage implements EnvelopeItemInterface
{
public function serialize()
{
return '';
}

public function unserialize($serialized)
{
// noop
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CHANGELOG
=========

4.2.0
-----

* `ValidationMiddleware::handle()` and `SendMessageMiddleware::handle()` now require an `Envelope` object
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
3 changes: 2 additions & 1 deletion src/Symfony/Component/Messenger/EnvelopeItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

/**
* An envelope item related to a message.
*
* This item must be serializable for transport.
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*
* @experimental in 4.1
*/
interface EnvelopeItemInterface extends \Serializable
interface EnvelopeItemInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,4 @@ public function getGroups()
{
return $this->groups;
}

public function serialize()
{
$isGroupSequence = $this->groups instanceof GroupSequence;

return serialize(array(
'groups' => $isGroupSequence ? $this->groups->groups : $this->groups,
'is_group_sequence' => $isGroupSequence,
));
}

public function unserialize($serialized)
{
list(
'groups' => $groups,
'is_group_sequence' => $isGroupSequence
) = unserialize($serialized, array('allowed_classes' => false));

$this->__construct($isGroupSequence ? new GroupSequence($groups) : $groups);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function testSerializable()
{
$config = new SerializerConfiguration(array(ObjectNormalizer::GROUPS => array('Default', 'Extra')));

$this->assertTrue(is_subclass_of(SerializerConfiguration::class, \Serializable::class, true));
$this->assertEquals($config, unserialize(serialize($config)));
}
}
15 changes: 0 additions & 15 deletions src/Symfony/Component/Messenger/Tests/Fixtures/AnEnvelopeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,4 @@

class AnEnvelopeItem implements EnvelopeItemInterface
{
/**
* {@inheritdoc}
*/
public function serialize()
{
return '';
}

/**
* {@inheritdoc}
*/
public function unserialize($serialized)
{
// noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function testConfig()

public function testSerializable()
{
$this->assertTrue(is_subclass_of(ValidationConfiguration::class, \Serializable::class, true));
$this->assertEquals($config = new ValidationConfiguration(array('Default', 'Extra')), unserialize(serialize($config)));
$this->assertEquals($config = new ValidationConfiguration(new GroupSequence(array('Default', 'Then'))), unserialize(serialize($config)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public function testEncodedWithSerializationConfiguration()
$this->assertArrayHasKey('type', $encoded['headers']);
$this->assertEquals(DummyMessage::class, $encoded['headers']['type']);
$this->assertArrayHasKey('X-Message-Envelope-Items', $encoded['headers']);
$this->assertSame('a:2:{s:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration";C:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration":59:{a:1:{s:7:"context";a:1:{s:6:"groups";a:1:{i:0;s:3:"foo";}}}}s:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration";C:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration":82:{a:2:{s:6:"groups";a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}s:17:"is_group_sequence";b:0;}}}', $encoded['headers']['X-Message-Envelope-Items']);
$this->assertSame('a:2:{s:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration";O:75:"Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration":1:{s:84:"'."\0".'Symfony\Component\Messenger\Transport\Serialization\SerializerConfiguration'."\0".'context";a:1:{s:6:"groups";a:1:{i:0;s:3:"foo";}}}s:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration";O:76:"Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration":1:{s:84:"'."\0".'Symfony\Component\Messenger\Middleware\Configuration\ValidationConfiguration'."\0".'groups";a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}}}', $encoded['headers']['X-Message-Envelope-Items']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,4 @@ public function getContext(): array
{
return $this->context;
}

public function serialize()
{
return serialize(array('context' => $this->context));
}

public function unserialize($serialized)
{
list('context' => $context) = unserialize($serialized, array('allowed_classes' => false));

$this->__construct($context);
}
}
0