Skip to content

Commit 268e650

Browse files
committed
Uses a messenger serializer, not an individual encoder/decoder
1 parent e980ce4 commit 268e650

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
<service id="messenger.transport.amqp.factory" class="Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory">
6464
<argument type="service" id="messenger.transport.encoder" />
65-
<argument type="service" id="messenger.transport.decoder" />
6665
<argument>%kernel.debug%</argument>
6766

6867
<tag name="messenger.transport_factory" />

src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/AmqpTransportFactoryTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
1818
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
1919
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
20+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2021

2122
class AmqpTransportFactoryTest extends TestCase
2223
{
2324
public function testSupportsOnlyAmqpTransports()
2425
{
2526
$factory = new AmqpTransportFactory(
26-
$this->getMockBuilder(EncoderInterface::class)->getMock(),
27-
$this->getMockBuilder(DecoderInterface::class)->getMock(),
27+
$this->getMockBuilder(SerializerInterface::class)->getMock(),
2828
true
2929
);
3030

@@ -36,12 +36,11 @@ public function testSupportsOnlyAmqpTransports()
3636
public function testItCreatesTheTransport()
3737
{
3838
$factory = new AmqpTransportFactory(
39-
$encoder = $this->getMockBuilder(EncoderInterface::class)->getMock(),
40-
$decoder = $this->getMockBuilder(DecoderInterface::class)->getMock(),
39+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
4140
true
4241
);
4342

44-
$expectedTransport = new AmqpTransport($encoder, $decoder, Connection::fromDsn('amqp://localhost', array('foo' => 'bar'), true), array('foo' => 'bar'), true);
43+
$expectedTransport = new AmqpTransport($serializer, Connection::fromDsn('amqp://localhost', array('foo' => 'bar'), true));
4544

4645
$this->assertEquals($expectedTransport, $factory->createTransport('amqp://localhost', array('foo' => 'bar')));
4746
}

src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/AmqpTransportTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
1919
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
2020
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
21+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2122
use Symfony\Component\Messenger\Transport\TransportInterface;
2223

2324
/**
@@ -35,8 +36,7 @@ public function testItIsATransport()
3536
public function testReceivesMessages()
3637
{
3738
$transport = $this->getTransport(
38-
null,
39-
$decoder = $this->getMockBuilder(DecoderInterface::class)->getMock(),
39+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
4040
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
4141
);
4242

@@ -46,7 +46,7 @@ public function testReceivesMessages()
4646
$amqpEnvelope->method('getBody')->willReturn('body');
4747
$amqpEnvelope->method('getHeaders')->willReturn(array('my' => 'header'));
4848

49-
$decoder->method('decode')->with(array('body' => 'body', 'headers' => array('my' => 'header')))->willReturn(Envelope::wrap($decodedMessage));
49+
$serializer->method('decode')->with(array('body' => 'body', 'headers' => array('my' => 'header')))->willReturn(Envelope::wrap($decodedMessage));
5050
$connection->method('get')->willReturn($amqpEnvelope);
5151

5252
$transport->receive(function (Envelope $envelope) use ($transport, $decodedMessage) {
@@ -56,12 +56,11 @@ public function testReceivesMessages()
5656
});
5757
}
5858

59-
private function getTransport(EncoderInterface $encoder = null, DecoderInterface $decoder = null, Connection $connection = null)
59+
private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
6060
{
61-
$encoder = $encoder ?: $this->getMockBuilder(EncoderInterface::class)->getMock();
62-
$decoder = $decoder ?: $this->getMockBuilder(DecoderInterface::class)->getMock();
61+
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
6362
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
6463

65-
return new AmqpTransport($encoder, $decoder, $connection);
64+
return new AmqpTransport($serializer, $connection);
6665
}
6766
}

src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransport.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414
use Symfony\Component\Messenger\Envelope;
1515
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
1616
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
17+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1718
use Symfony\Component\Messenger\Transport\TransportInterface;
1819

1920
/**
2021
* @author Nicolas Grekas <p@tchwork.com>
2122
*/
2223
class AmqpTransport implements TransportInterface
2324
{
24-
private $encoder;
25-
private $decoder;
25+
private $serializer;
2626
private $connection;
2727
private $receiver;
2828
private $sender;
2929

30-
public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, Connection $connection)
30+
public function __construct(SerializerInterface $serializer, Connection $connection)
3131
{
32-
$this->encoder = $encoder;
33-
$this->decoder = $decoder;
32+
$this->serializer = $serializer;
3433
$this->connection = $connection;
3534
}
3635

@@ -60,11 +59,11 @@ public function send(Envelope $envelope): void
6059

6160
private function getReceiver()
6261
{
63-
return $this->receiver = new AmqpReceiver($this->decoder, $this->connection);
62+
return $this->receiver = new AmqpReceiver($this->serializer, $this->connection);
6463
}
6564

6665
private function getSender()
6766
{
68-
return $this->sender = new AmqpSender($this->encoder, $this->connection);
67+
return $this->sender = new AmqpSender($this->serializer, $this->connection);
6968
}
7069
}

src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpTransportFactory.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
1515
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
16+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1617
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
1718
use Symfony\Component\Messenger\Transport\TransportInterface;
1819

@@ -21,20 +22,18 @@
2122
*/
2223
class AmqpTransportFactory implements TransportFactoryInterface
2324
{
24-
private $encoder;
25-
private $decoder;
25+
private $serializer;
2626
private $debug;
2727

28-
public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, bool $debug)
28+
public function __construct(SerializerInterface $serializer, bool $debug)
2929
{
30-
$this->encoder = $encoder;
31-
$this->decoder = $decoder;
30+
$this->serializer = $serializer;
3231
$this->debug = $debug;
3332
}
3433

3534
public function createTransport(string $dsn, array $options): TransportInterface
3635
{
37-
return new AmqpTransport($this->encoder, $this->decoder, Connection::fromDsn($dsn, $options, $this->debug));
36+
return new AmqpTransport($this->serializer, Connection::fromDsn($dsn, $options, $this->debug));
3837
}
3938

4039
public function supports(string $dsn, array $options): bool

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1818
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1919
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
20-
use Symfony\Component\Serializer\SerializerInterface;
20+
use Symfony\Component\Serializer\SerializerInterface as SymfonySerializerInterface;
2121

2222
/**
2323
* @author Samuel Roze <samuel.roze@gmail.com>
2424
*/
25-
class Serializer implements DecoderInterface, EncoderInterface
25+
class Serializer implements SerializerInterface
2626
{
2727
private $serializer;
2828
private $format;
2929
private $context;
3030

31-
public function __construct(SerializerInterface $serializer, string $format = 'json', array $context = array())
31+
public function __construct(SymfonySerializerInterface $serializer, string $format = 'json', array $context = array())
3232
{
3333
$this->serializer = $serializer;
3434
$this->format = $format;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Transport\Serialization;
13+
14+
/**
15+
* @author Samuel Roze <samuel.roze@gmail.com>
16+
*/
17+
interface SerializerInterface extends DecoderInterface, EncoderInterface
18+
{
19+
}

0 commit comments

Comments
 (0)