From 9be84326d273794cbdd4d88de90b396b41dac341 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 1 Mar 2018 16:26:39 +0200 Subject: [PATCH] [client] Simple Client should not depend on amqp-ext. --- pkg/simple-client/SimpleClient.php | 79 ++++++++++++++++++++++++------ pkg/simple-client/composer.json | 2 +- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index 5f50396ff..640211781 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -2,6 +2,9 @@ namespace Enqueue\SimpleClient; +use Enqueue\AmqpBunny\AmqpConnectionFactory as AmqpBunnyConnectionFactory; +use Enqueue\AmqpExt\AmqpConnectionFactory as AmqpExtConnectionFactory; +use Enqueue\AmqpLib\AmqpConnectionFactory as AmqpLibConnectionFactory; use Enqueue\Client\ArrayProcessorRegistry; use Enqueue\Client\Config; use Enqueue\Client\DelegateProcessor; @@ -13,15 +16,24 @@ use Enqueue\Consumption\CallbackProcessor; use Enqueue\Consumption\ExtensionInterface; use Enqueue\Consumption\QueueConsumer; +use Enqueue\Dbal\DbalConnectionFactory; use Enqueue\Dbal\Symfony\DbalTransportFactory; +use Enqueue\Fs\FsConnectionFactory; use Enqueue\Fs\Symfony\FsTransportFactory; +use Enqueue\Gps\GpsConnectionFactory; +use Enqueue\Gps\Symfony\GpsTransportFactory; +use Enqueue\Null\Symfony\NullTransportFactory; +use Enqueue\Redis\RedisConnectionFactory; use Enqueue\Redis\Symfony\RedisTransportFactory; use Enqueue\Rpc\Promise; +use Enqueue\Sqs\SqsConnectionFactory; use Enqueue\Sqs\Symfony\SqsTransportFactory; +use Enqueue\Stomp\StompConnectionFactory; use Enqueue\Stomp\Symfony\RabbitMqStompTransportFactory; use Enqueue\Stomp\Symfony\StompTransportFactory; use Enqueue\Symfony\AmqpTransportFactory; use Enqueue\Symfony\DefaultTransportFactory; +use Enqueue\Symfony\MissingTransportFactory; use Enqueue\Symfony\RabbitMqAmqpTransportFactory; use Interop\Queue\PsrContext; use Interop\Queue\PsrProcessor; @@ -283,26 +295,61 @@ private function buildContainer($config, ContainerBuilder $container) */ private function buildContainerExtension() { - $map = [ - 'default' => DefaultTransportFactory::class, - 'dbal' => DbalTransportFactory::class, - 'fs' => FsTransportFactory::class, - 'redis' => RedisTransportFactory::class, - 'stomp' => StompTransportFactory::class, - 'rabbitmq_stomp' => RabbitMqStompTransportFactory::class, - 'sqs' => SqsTransportFactory::class, - ]; - $extension = new SimpleClientContainerExtension(); - foreach ($map as $name => $factoryClass) { - if (class_exists($factoryClass)) { - $extension->addTransportFactory(new $factoryClass($name)); - } + $extension->addTransportFactory(new DefaultTransportFactory('default')); + $extension->addTransportFactory(new NullTransportFactory('null')); + + if (class_exists(StompConnectionFactory::class)) { + $extension->addTransportFactory(new StompTransportFactory('stomp')); + $extension->addTransportFactory(new RabbitMqStompTransportFactory('rabbitmq_stomp')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('stomp', ['enqueue/stomp'])); + $extension->addTransportFactory(new MissingTransportFactory('rabbitmq_stomp', ['enqueue/stomp'])); } - $extension->addTransportFactory(new AmqpTransportFactory('amqp')); - $extension->addTransportFactory(new RabbitMqAmqpTransportFactory('rabbitmq_amqp')); + if ( + class_exists(AmqpBunnyConnectionFactory::class) || + class_exists(AmqpExtConnectionFactory::class) || + class_exists(AmqpLibConnectionFactory::class) + ) { + $extension->addTransportFactory(new AmqpTransportFactory('amqp')); + $extension->addTransportFactory(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)); + } + + if (class_exists(FsConnectionFactory::class)) { + $extension->addTransportFactory(new FsTransportFactory('fs')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('fs', ['enqueue/fs'])); + } + + if (class_exists(RedisConnectionFactory::class)) { + $extension->addTransportFactory(new RedisTransportFactory('redis')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('redis', ['enqueue/redis'])); + } + + if (class_exists(DbalConnectionFactory::class)) { + $extension->addTransportFactory(new DbalTransportFactory('dbal')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('dbal', ['enqueue/dbal'])); + } + + if (class_exists(SqsConnectionFactory::class)) { + $extension->addTransportFactory(new SqsTransportFactory('sqs')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('sqs', ['enqueue/sqs'])); + } + + if (class_exists(GpsConnectionFactory::class)) { + $extension->addTransportFactory(new GpsTransportFactory('gps')); + } else { + $extension->addTransportFactory(new MissingTransportFactory('gps', ['enqueue/gps'])); + } return $extension; } diff --git a/pkg/simple-client/composer.json b/pkg/simple-client/composer.json index a25a00a59..3986b0f8e 100644 --- a/pkg/simple-client/composer.json +++ b/pkg/simple-client/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.6", - "enqueue/enqueue": "^0.8@dev", + "enqueue/enqueue": "^0.8.21@dev", "symfony/dependency-injection": "^2.8|^3|^4", "symfony/config": "^2.8|^3|^4", "symfony/console": "^2.8|^3|^4"