Skip to content

Commit 2cb5b5b

Browse files
weaverryanfabpot
authored andcommitted
Making the serializer configurable by transport
1 parent 58214ba commit 2cb5b5b

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ CHANGELOG
44
4.3.0
55
-----
66

7+
* [BC BREAK] The `TransportFactoryInterface::createTransport()` signature
8+
changed: a required 3rd `SerializerInterface` argument was added.
79
* Added a new `SyncTransport` along with `ForceCallHandlersStamp` to
810
explicitly handle messages synchronously.
911
* Added optional parameter `prefetch_count` in connection configuration,
10-
to setup channel prefetch count
12+
to setup channel prefetch count.
1113
* New classes: `RoutableMessageBus`, `AddBusNameStampMiddleware`
1214
and `BusNameStamp` were added, which allow you to add a bus identifier
1315
to the `Envelope` then find the correct bus when receiving from

Tests/Transport/AmqpExt/AmqpTransportFactoryTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class AmqpTransportFactoryTest extends TestCase
2121
{
2222
public function testSupportsOnlyAmqpTransports()
2323
{
24-
$factory = new AmqpTransportFactory(
25-
$this->getMockBuilder(SerializerInterface::class)->getMock()
26-
);
24+
$factory = new AmqpTransportFactory();
2725

2826
$this->assertTrue($factory->supports('amqp://localhost', []));
2927
$this->assertFalse($factory->supports('sqs://localhost', []));
@@ -32,12 +30,11 @@ public function testSupportsOnlyAmqpTransports()
3230

3331
public function testItCreatesTheTransport()
3432
{
35-
$factory = new AmqpTransportFactory(
36-
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock()
37-
);
33+
$factory = new AmqpTransportFactory();
34+
$serializer = $this->createMock(SerializerInterface::class);
3835

3936
$expectedTransport = new AmqpTransport(Connection::fromDsn('amqp://localhost', ['foo' => 'bar']), $serializer);
4037

41-
$this->assertEquals($expectedTransport, $factory->createTransport('amqp://localhost', ['foo' => 'bar']));
38+
$this->assertEquals($expectedTransport, $factory->createTransport('amqp://localhost', ['foo' => 'bar'], $serializer));
4239
}
4340
}

Transport/AmqpExt/AmqpTransportFactory.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

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

14-
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
1514
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1615
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
1716
use Symfony\Component\Messenger\Transport\TransportInterface;
@@ -23,16 +22,9 @@
2322
*/
2423
class AmqpTransportFactory implements TransportFactoryInterface
2524
{
26-
private $serializer;
27-
28-
public function __construct(SerializerInterface $serializer = null)
29-
{
30-
$this->serializer = $serializer ?? new PhpSerializer();
31-
}
32-
33-
public function createTransport(string $dsn, array $options): TransportInterface
25+
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
3426
{
35-
return new AmqpTransport(Connection::fromDsn($dsn, $options), $this->serializer);
27+
return new AmqpTransport(Connection::fromDsn($dsn, $options), $serializer);
3628
}
3729

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

Transport/TransportFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Transport;
1313

1414
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
15+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
1516

1617
/**
1718
* @author Samuel Roze <[email protected]>
@@ -30,11 +31,11 @@ public function __construct(iterable $factories)
3031
$this->factories = $factories;
3132
}
3233

33-
public function createTransport(string $dsn, array $options): TransportInterface
34+
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
3435
{
3536
foreach ($this->factories as $factory) {
3637
if ($factory->supports($dsn, $options)) {
37-
return $factory->createTransport($dsn, $options);
38+
return $factory->createTransport($dsn, $options, $serializer);
3839
}
3940
}
4041

Transport/TransportFactoryInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Messenger\Transport;
1313

14+
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
15+
1416
/**
1517
* Creates a Messenger transport.
1618
*
@@ -20,7 +22,7 @@
2022
*/
2123
interface TransportFactoryInterface
2224
{
23-
public function createTransport(string $dsn, array $options): TransportInterface;
25+
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface;
2426

2527
public function supports(string $dsn, array $options): bool;
2628
}

0 commit comments

Comments
 (0)