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

Skip to content

Commit 29d887f

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

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransport;
1616
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory;
1717
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
18-
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
19-
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
18+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2019

2120
class AmqpTransportFactoryTest extends TestCase
2221
{
2322
public function testSupportsOnlyAmqpTransports()
2423
{
2524
$factory = new AmqpTransportFactory(
26-
$this->getMockBuilder(EncoderInterface::class)->getMock(),
27-
$this->getMockBuilder(DecoderInterface::class)->getMock(),
25+
$this->getMockBuilder(SerializerInterface::class)->getMock(),
2826
true
2927
);
3028

@@ -36,12 +34,11 @@ public function testSupportsOnlyAmqpTransports()
3634
public function testItCreatesTheTransport()
3735
{
3836
$factory = new AmqpTransportFactory(
39-
$encoder = $this->getMockBuilder(EncoderInterface::class)->getMock(),
40-
$decoder = $this->getMockBuilder(DecoderInterface::class)->getMock(),
37+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
4138
true
4239
);
4340

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

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

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
1717
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransport;
1818
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
19-
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
20-
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
19+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
2120
use Symfony\Component\Messenger\Transport\TransportInterface;
2221

2322
/**
@@ -35,8 +34,7 @@ public function testItIsATransport()
3534
public function testReceivesMessages()
3635
{
3736
$transport = $this->getTransport(
38-
null,
39-
$decoder = $this->getMockBuilder(DecoderInterface::class)->getMock(),
37+
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
4038
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
4139
);
4240

@@ -46,7 +44,7 @@ public function testReceivesMessages()
4644
$amqpEnvelope->method('getBody')->willReturn('body');
4745
$amqpEnvelope->method('getHeaders')->willReturn(array('my' => 'header'));
4846

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

5250
$transport->receive(function (Envelope $envelope) use ($transport, $decodedMessage) {
@@ -56,12 +54,11 @@ public function testReceivesMessages()
5654
});
5755
}
5856

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

65-
return new AmqpTransport($encoder, $decoder, $connection);
62+
return new AmqpTransport($serializer, $connection);
6663
}
6764
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,22 @@
1212
namespace Symfony\Component\Messenger\Transport\AmqpExt;
1313

1414
use Symfony\Component\Messenger\Envelope;
15-
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
16-
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
15+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1716
use Symfony\Component\Messenger\Transport\TransportInterface;
1817

1918
/**
2019
* @author Nicolas Grekas <[email protected]>
2120
*/
2221
class AmqpTransport implements TransportInterface
2322
{
24-
private $encoder;
25-
private $decoder;
23+
private $serializer;
2624
private $connection;
2725
private $receiver;
2826
private $sender;
2927

30-
public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, Connection $connection)
28+
public function __construct(SerializerInterface $serializer, Connection $connection)
3129
{
32-
$this->encoder = $encoder;
33-
$this->decoder = $decoder;
30+
$this->serializer = $serializer;
3431
$this->connection = $connection;
3532
}
3633

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

6158
private function getReceiver()
6259
{
63-
return $this->receiver = new AmqpReceiver($this->decoder, $this->connection);
60+
return $this->receiver = new AmqpReceiver($this->serializer, $this->connection);
6461
}
6562

6663
private function getSender()
6764
{
68-
return $this->sender = new AmqpSender($this->encoder, $this->connection);
65+
return $this->sender = new AmqpSender($this->serializer, $this->connection);
6966
}
7067
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace Symfony\Component\Messenger\Transport\AmqpExt;
1313

14-
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface;
15-
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface;
14+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1615
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
1716
use Symfony\Component\Messenger\Transport\TransportInterface;
1817

@@ -21,20 +20,18 @@
2120
*/
2221
class AmqpTransportFactory implements TransportFactoryInterface
2322
{
24-
private $encoder;
25-
private $decoder;
23+
private $serializer;
2624
private $debug;
2725

28-
public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, bool $debug)
26+
public function __construct(SerializerInterface $serializer, bool $debug)
2927
{
30-
$this->encoder = $encoder;
31-
$this->decoder = $decoder;
28+
$this->serializer = $serializer;
3229
$this->debug = $debug;
3330
}
3431

3532
public function createTransport(string $dsn, array $options): TransportInterface
3633
{
37-
return new AmqpTransport($this->encoder, $this->decoder, Connection::fromDsn($dsn, $options, $this->debug));
34+
return new AmqpTransport($this->serializer, Connection::fromDsn($dsn, $options, $this->debug));
3835
}
3936

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

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

Lines changed: 3 additions & 3 deletions
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 <[email protected]>
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;
Lines changed: 19 additions & 0 deletions
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 <[email protected]>
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 <[email protected]>
16+
*/
17+
interface SerializerInterface extends DecoderInterface, EncoderInterface
18+
{
19+
}

0 commit comments

Comments
 (0)