Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93bb665

Browse files
committed
feature #28247 [Messenger] Don't make EnvelopeItemInterface extend Serializable (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Messenger] Don't make EnvelopeItemInterface extend Serializable | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes (on experimental API) | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - `Serializable` is a broken interface, see e.g. https://externals.io/message/98834 I don't think we should force ppl to implement it anywhere. Actually, it isn't required to be able to serialize an object, and it doesn't enforce making a class serializable (as the `serialize()` method can throw). What was the purpose of the removed logic? ping @sroze @ogizanagi Commits ------- 2beda89 [Messenger] Don't make EnvelopeItemInterface extend Serializable
2 parents ff1727e + 2beda89 commit 93bb665

File tree

10 files changed

+13
-60
lines changed

10 files changed

+13
-60
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ FrameworkBundle
8787
Messenger
8888
---------
8989

90+
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
9091
* 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.
9192

9293
Security

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
/**
1818
* Marker config for a received message.
19+
*
1920
* This is mainly used by the `SendMessageMiddleware` middleware to identify
2021
* a message should not be sent if it was just received.
2122
*
@@ -25,13 +26,4 @@
2526
*/
2627
final class ReceivedMessage implements EnvelopeItemInterface
2728
{
28-
public function serialize()
29-
{
30-
return '';
31-
}
32-
33-
public function unserialize($serialized)
34-
{
35-
// noop
36-
}
3729
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CHANGELOG
2+
=========
3+
4+
4.2.0
5+
-----
6+
7+
* `ValidationMiddleware::handle()` and `SendMessageMiddleware::handle()` now require an `Envelope` object
8+
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore

src/Symfony/Component/Messenger/EnvelopeItemInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
/**
1515
* An envelope item related to a message.
16+
*
1617
* This item must be serializable for transport.
1718
*
1819
* @author Maxime Steinhausser <[email protected]>
1920
*
2021
* @experimental in 4.1
2122
*/
22-
interface EnvelopeItemInterface extends \Serializable
23+
interface EnvelopeItemInterface
2324
{
2425
}

src/Symfony/Component/Messenger/Middleware/Configuration/ValidationConfiguration.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,4 @@ public function getGroups()
3535
{
3636
return $this->groups;
3737
}
38-
39-
public function serialize()
40-
{
41-
$isGroupSequence = $this->groups instanceof GroupSequence;
42-
43-
return serialize(array(
44-
'groups' => $isGroupSequence ? $this->groups->groups : $this->groups,
45-
'is_group_sequence' => $isGroupSequence,
46-
));
47-
}
48-
49-
public function unserialize($serialized)
50-
{
51-
list(
52-
'groups' => $groups,
53-
'is_group_sequence' => $isGroupSequence
54-
) = unserialize($serialized, array('allowed_classes' => false));
55-
56-
$this->__construct($isGroupSequence ? new GroupSequence($groups) : $groups);
57-
}
5838
}

src/Symfony/Component/Messenger/Tests/Asynchronous/Transport/Serialization/SerializerConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function testSerializable()
2424
{
2525
$config = new SerializerConfiguration(array(ObjectNormalizer::GROUPS => array('Default', 'Extra')));
2626

27-
$this->assertTrue(is_subclass_of(SerializerConfiguration::class, \Serializable::class, true));
2827
$this->assertEquals($config, unserialize(serialize($config)));
2928
}
3029
}

src/Symfony/Component/Messenger/Tests/Fixtures/AnEnvelopeItem.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,4 @@
1515

1616
class AnEnvelopeItem implements EnvelopeItemInterface
1717
{
18-
/**
19-
* {@inheritdoc}
20-
*/
21-
public function serialize()
22-
{
23-
return '';
24-
}
25-
26-
/**
27-
* {@inheritdoc}
28-
*/
29-
public function unserialize($serialized)
30-
{
31-
// noop
32-
}
3318
}

src/Symfony/Component/Messenger/Tests/Middleware/Configuration/ValidationConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function testConfig()
3131

3232
public function testSerializable()
3333
{
34-
$this->assertTrue(is_subclass_of(ValidationConfiguration::class, \Serializable::class, true));
3534
$this->assertEquals($config = new ValidationConfiguration(array('Default', 'Extra')), unserialize(serialize($config)));
3635
$this->assertEquals($config = new ValidationConfiguration(new GroupSequence(array('Default', 'Then'))), unserialize(serialize($config)));
3736
}

src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ public function testEncodedWithSerializationConfiguration()
9898
$this->assertArrayHasKey('type', $encoded['headers']);
9999
$this->assertEquals(DummyMessage::class, $encoded['headers']['type']);
100100
$this->assertArrayHasKey('X-Message-Envelope-Items', $encoded['headers']);
101-
$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']);
101+
$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']);
102102
}
103103
}

src/Symfony/Component/Messenger/Transport/Serialization/SerializerConfiguration.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,4 @@ public function getContext(): array
3131
{
3232
return $this->context;
3333
}
34-
35-
public function serialize()
36-
{
37-
return serialize(array('context' => $this->context));
38-
}
39-
40-
public function unserialize($serialized)
41-
{
42-
list('context' => $context) = unserialize($serialized, array('allowed_classes' => false));
43-
44-
$this->__construct($context);
45-
}
4634
}

0 commit comments

Comments
 (0)