Skip to content
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

[bundle] fix for "Transport factory with such name already added" #388

Merged
merged 1 commit into from
Mar 1, 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
17 changes: 14 additions & 3 deletions pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,24 @@ public function addTransportFactory(TransportFactoryInterface $transportFactory)
{
$name = $transportFactory->getName();

if (empty($name)) {
throw new \LogicException('Transport factory name cannot be empty');
}
if (array_key_exists($name, $this->factories)) {
throw new \LogicException(sprintf('Transport factory with such name already added. Name %s', $name));
}

$this->setTransportFactory($transportFactory);
}

/**
* @param TransportFactoryInterface $transportFactory
*/
public function setTransportFactory(TransportFactoryInterface $transportFactory)
{
$name = $transportFactory->getName();

if (empty($name)) {
throw new \LogicException('Transport factory name cannot be empty');
}

$this->factories[$name] = $transportFactory;
}

Expand Down
36 changes: 18 additions & 18 deletions pkg/enqueue-bundle/EnqueueBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,54 +54,54 @@ public function build(ContainerBuilder $container)
$extension = $container->getExtension('enqueue');

if (class_exists(StompConnectionFactory::class)) {
$extension->addTransportFactory(new StompTransportFactory('stomp'));
$extension->addTransportFactory(new RabbitMqStompTransportFactory('rabbitmq_stomp'));
$extension->setTransportFactory(new StompTransportFactory('stomp'));
$extension->setTransportFactory(new RabbitMqStompTransportFactory('rabbitmq_stomp'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('stomp', ['enqueue/stomp']));
$extension->addTransportFactory(new MissingTransportFactory('rabbitmq_stomp', ['enqueue/stomp']));
$extension->setTransportFactory(new MissingTransportFactory('stomp', ['enqueue/stomp']));
$extension->setTransportFactory(new MissingTransportFactory('rabbitmq_stomp', ['enqueue/stomp']));
}

if (
class_exists(AmqpBunnyConnectionFactory::class) ||
class_exists(AmqpExtConnectionFactory::class) ||
class_exists(AmqpLibConnectionFactory::class)
) {
$extension->addTransportFactory(new AmqpTransportFactory('amqp'));
$extension->addTransportFactory(new RabbitMqAmqpTransportFactory('rabbitmq_amqp'));
$extension->setTransportFactory(new AmqpTransportFactory('amqp'));
$extension->setTransportFactory(new RabbitMqAmqpTransportFactory('rabbitmq_amqp'));
} else {
$amppPackages = ['enqueue/amqp-ext', 'enqueue/amqp-bunny', 'enqueue/amqp-lib'];
$extension->addTransportFactory(new MissingTransportFactory('amqp', $amppPackages));
$extension->addTransportFactory(new MissingTransportFactory('rabbitmq_amqp', $amppPackages));
$extension->setTransportFactory(new MissingTransportFactory('amqp', $amppPackages));
$extension->setTransportFactory(new MissingTransportFactory('rabbitmq_amqp', $amppPackages));
}

if (class_exists(FsConnectionFactory::class)) {
$extension->addTransportFactory(new FsTransportFactory('fs'));
$extension->setTransportFactory(new FsTransportFactory('fs'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('fs', ['enqueue/fs']));
$extension->setTransportFactory(new MissingTransportFactory('fs', ['enqueue/fs']));
}

if (class_exists(RedisConnectionFactory::class)) {
$extension->addTransportFactory(new RedisTransportFactory('redis'));
$extension->setTransportFactory(new RedisTransportFactory('redis'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('redis', ['enqueue/redis']));
$extension->setTransportFactory(new MissingTransportFactory('redis', ['enqueue/redis']));
}

if (class_exists(DbalConnectionFactory::class)) {
$extension->addTransportFactory(new DbalTransportFactory('dbal'));
$extension->setTransportFactory(new DbalTransportFactory('dbal'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('dbal', ['enqueue/dbal']));
$extension->setTransportFactory(new MissingTransportFactory('dbal', ['enqueue/dbal']));
}

if (class_exists(SqsConnectionFactory::class)) {
$extension->addTransportFactory(new SqsTransportFactory('sqs'));
$extension->setTransportFactory(new SqsTransportFactory('sqs'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('sqs', ['enqueue/sqs']));
$extension->setTransportFactory(new MissingTransportFactory('sqs', ['enqueue/sqs']));
}

if (class_exists(GpsConnectionFactory::class)) {
$extension->addTransportFactory(new GpsTransportFactory('gps'));
$extension->setTransportFactory(new GpsTransportFactory('gps'));
} else {
$extension->addTransportFactory(new MissingTransportFactory('gps', ['enqueue/gps']));
$extension->setTransportFactory(new MissingTransportFactory('gps', ['enqueue/gps']));
}

$container->addCompilerPass(new AsyncEventsPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
Expand Down
18 changes: 9 additions & 9 deletions pkg/enqueue-bundle/Tests/Unit/EnqueueBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public function testShouldRegisterStompAndRabbitMqStompTransportFactories()

$extensionMock
->expects($this->at(0))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(StompTransportFactory::class))
;
$extensionMock
->expects($this->at(1))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(RabbitMqStompTransportFactory::class))
;

Expand All @@ -120,15 +120,15 @@ public function testShouldRegisterAmqpAndRabbitMqAmqpTransportFactories()

$extensionMock
->expects($this->at(2))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(AmqpTransportFactory::class))
->willReturnCallback(function (AmqpTransportFactory $factory) {
$this->assertSame('amqp', $factory->getName());
})
;
$extensionMock
->expects($this->at(3))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(RabbitMqAmqpTransportFactory::class))
->willReturnCallback(function (RabbitMqAmqpTransportFactory $factory) {
$this->assertSame('rabbitmq_amqp', $factory->getName());
Expand All @@ -148,7 +148,7 @@ public function testShouldRegisterFSTransportFactory()

$extensionMock
->expects($this->at(4))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(FsTransportFactory::class))
;

Expand All @@ -165,7 +165,7 @@ public function testShouldRegisterRedisTransportFactory()

$extensionMock
->expects($this->at(5))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(RedisTransportFactory::class))
;

Expand All @@ -182,7 +182,7 @@ public function testShouldRegisterDbalTransportFactory()

$extensionMock
->expects($this->at(6))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(DbalTransportFactory::class))
;

Expand All @@ -199,7 +199,7 @@ public function testShouldRegisterSqsTransportFactory()

$extensionMock
->expects($this->at(7))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(SqsTransportFactory::class))
;

Expand All @@ -216,7 +216,7 @@ public function testShouldRegisterGpsTransportFactory()

$extensionMock
->expects($this->at(8))
->method('addTransportFactory')
->method('setTransportFactory')
->with($this->isInstanceOf(GpsTransportFactory::class))
;

Expand Down