+ * + * @deprecated since version 3.4, to be removed in 4.0. Use Symfony\Component\Lock\Store\SemaphoreStore or Symfony\Component\Lock\Store\FlockStore instead. + */ +class LockHandler +{ + private $file; + private $handle; + + /** + * @param string $name The lock name + * @param string|null $lockPath The directory to store the lock. Default values will use temporary directory + * + * @throws IOException If the lock directory could not be created or is not writable + */ + public function __construct($name, $lockPath = null) + { + $lockPath = $lockPath ?: sys_get_temp_dir(); + + if (!is_dir($lockPath)) { + $fs = new Filesystem(); + $fs->mkdir($lockPath); + } + + if (!is_writable($lockPath)) { + throw new IOException(sprintf('The directory "%s" is not writable.', $lockPath), 0, null, $lockPath); + } + + $this->file = sprintf('%s/sf.%s.%s.lock', $lockPath, preg_replace('/[^a-z0-9\._-]+/i', '-', $name), hash('sha256', $name)); + } + + /** + * Lock the resource. + * + * @param bool $blocking Wait until the lock is released + * + * @throws IOException If the lock file could not be created or opened + * + * @return bool Returns true if the lock was acquired, false otherwise + */ + public function lock($blocking = false) + { + if ($this->handle) { + return true; + } + + $error = null; + + // Silence error reporting + set_error_handler(function ($errno, $msg) use (&$error) { + $error = $msg; + }); + + if (!$this->handle = fopen($this->file, 'r')) { + if ($this->handle = fopen($this->file, 'x')) { + chmod($this->file, 0444); + } elseif (!$this->handle = fopen($this->file, 'r')) { + usleep(100); // Give some time for chmod() to complete + $this->handle = fopen($this->file, 'r'); + } + } + restore_error_handler(); + + if (!$this->handle) { + throw new IOException($error, 0, null, $this->file); + } + + // On Windows, even if PHP doc says the contrary, LOCK_NB works, see + // https://bugs.php.net/54129 + if (!flock($this->handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) { + fclose($this->handle); + $this->handle = null; + + return false; + } + + return true; + } + + /** + * Release the resource. + */ + public function release() + { + if ($this->handle) { + flock($this->handle, LOCK_UN | LOCK_NB); + fclose($this->handle); + $this->handle = null; + } + } +} diff --git a/pkg/fs/Lock.php b/pkg/fs/Lock.php new file mode 100644 index 000000000..02c2fbb76 --- /dev/null +++ b/pkg/fs/Lock.php @@ -0,0 +1,23 @@ +getName()); $context = new Definition(FsContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -100,6 +101,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(FsDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/fs/Tests/FsContextTest.php b/pkg/fs/Tests/FsContextTest.php index 5ce324a49..0d1ea4c63 100644 --- a/pkg/fs/Tests/FsContextTest.php +++ b/pkg/fs/Tests/FsContextTest.php @@ -182,34 +182,6 @@ public function testShouldAllowPurgeMessagesFromQueue() $this->assertEmpty(file_get_contents($tmpFile)); } - public function testShouldReleaseAllLocksOnClose() - { - new TempFile(sys_get_temp_dir().'/foo'); - new TempFile(sys_get_temp_dir().'/bar'); - - $context = new FsContext(sys_get_temp_dir(), 1, 0666); - - $fooQueue = $context->createQueue('foo'); - $barQueue = $context->createTopic('bar'); - - $this->assertAttributeCount(0, 'lockHandlers', $context); - - $context->workWithFile($fooQueue, 'r+', function () { - }); - $context->workWithFile($barQueue, 'r+', function () { - }); - $context->workWithFile($fooQueue, 'c+', function () { - }); - $context->workWithFile($barQueue, 'c+', function () { - }); - - $this->assertAttributeCount(2, 'lockHandlers', $context); - - $context->close(); - - $this->assertAttributeCount(0, 'lockHandlers', $context); - } - public function testShouldCreateFileOnFilesystemIfNotExistOnDeclareDestination() { $tmpFile = new TempFile(sys_get_temp_dir().'/'.uniqid()); diff --git a/pkg/fs/Tests/LegacyFilesystemLockTest.php b/pkg/fs/Tests/LegacyFilesystemLockTest.php new file mode 100644 index 000000000..c797bf41a --- /dev/null +++ b/pkg/fs/Tests/LegacyFilesystemLockTest.php @@ -0,0 +1,50 @@ +assertClassImplements(Lock::class, LegacyFilesystemLock::class); + } + + public function testShouldReleaseAllLocksOnClose() + { + $context = new FsContext(sys_get_temp_dir(), 1, 0666); + $fooQueue = $context->createQueue('foo'); + $barQueue = $context->createTopic('bar'); + + new TempFile(sys_get_temp_dir().'/foo'); + new TempFile(sys_get_temp_dir().'/bar'); + + $lock = new LegacyFilesystemLock(); + + $this->assertAttributeCount(0, 'lockHandlers', $lock); + + $lock->lock($fooQueue); + $this->assertAttributeCount(1, 'lockHandlers', $lock); + + $lock->release($fooQueue); + $this->assertAttributeCount(1, 'lockHandlers', $lock); + + $lock->lock($barQueue); + $lock->lock($fooQueue); + $lock->lock($barQueue); + + $this->assertAttributeCount(2, 'lockHandlers', $lock); + + $lock->releaseAll(); + + $this->assertAttributeCount(0, 'lockHandlers', $lock); + } +} diff --git a/pkg/fs/composer.json b/pkg/fs/composer.json index a76cbaca8..f9d481dd2 100644 --- a/pkg/fs/composer.json +++ b/pkg/fs/composer.json @@ -3,11 +3,12 @@ "type": "library", "description": "Enqueue Filesystem based transport", "keywords": ["messaging", "queue", "filesystem", "local"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", "queue-interop/queue-interop": "^0.6", - "symfony/filesystem": "^2.8|^3@stable", + "symfony/filesystem": "^2.8|^3|^4", "makasim/temp-file": "^0.2@stable" }, "require-dev": { @@ -16,9 +17,9 @@ "enqueue/null": "^0.7", "enqueue/test": "^0.7", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3@stable", - "symfony/config": "^2.8|^3@stable", - "symfony/phpunit-bridge": "^2.8|^3@stable" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4", + "symfony/phpunit-bridge": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Fs\\": "" }, diff --git a/pkg/gearman/composer.json b/pkg/gearman/composer.json index 4529a1197..85b8fc8bd 100644 --- a/pkg/gearman/composer.json +++ b/pkg/gearman/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Queue Gearman transport", "keywords": ["messaging", "queue", "german"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -15,8 +16,8 @@ "enqueue/enqueue": "^0.8@dev", "enqueue/null": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Gearman\\": "" }, diff --git a/pkg/gps/Symfony/GpsTransportFactory.php b/pkg/gps/Symfony/GpsTransportFactory.php index 1ad137a12..36c15e39b 100644 --- a/pkg/gps/Symfony/GpsTransportFactory.php +++ b/pkg/gps/Symfony/GpsTransportFactory.php @@ -94,6 +94,7 @@ public function createContext(ContainerBuilder $container, array $config) $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $context = new Definition(GpsContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -108,6 +109,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(GpsDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/gps/composer.json b/pkg/gps/composer.json index b9540a51c..f8cf4729c 100644 --- a/pkg/gps/composer.json +++ b/pkg/gps/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Google Cloud Pub/Sub Transport", "keywords": ["messaging", "queue", "google", "pubsub"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -14,8 +15,8 @@ "enqueue/test": "^0.8@dev", "enqueue/enqueue": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Gps\\": "" }, diff --git a/pkg/job-queue/Tests/Functional/app/AppKernel.php b/pkg/job-queue/Tests/Functional/app/AppKernel.php index ce21df0b8..0d60c665f 100644 --- a/pkg/job-queue/Tests/Functional/app/AppKernel.php +++ b/pkg/job-queue/Tests/Functional/app/AppKernel.php @@ -44,6 +44,21 @@ public function registerContainerConfiguration(LoaderInterface $loader) $loader->load(__DIR__.'/config/config.yml'); } + protected function getKernelParameters() + { + $parameters = parent::getKernelParameters(); + + // it works in all Symfony version, 2.8, 3.x, 4.x + $parameters['db.driver'] = getenv('DOCTRINE_DRIVER'); + $parameters['db.host'] = getenv('DOCTRINE_HOST'); + $parameters['db.port'] = getenv('DOCTRINE_PORT'); + $parameters['db.name'] = getenv('DOCTRINE_DB_NAME'); + $parameters['db.user'] = getenv('DOCTRINE_USER'); + $parameters['db.password'] = getenv('DOCTRINE_PASSWORD'); + + return $parameters; + } + protected function getContainerClass() { return parent::getContainerClass().'JobQueue'; diff --git a/pkg/job-queue/composer.json b/pkg/job-queue/composer.json index 816c5c164..8bf91d18f 100644 --- a/pkg/job-queue/composer.json +++ b/pkg/job-queue/composer.json @@ -3,10 +3,11 @@ "type": "library", "description": "Job Queue", "keywords": ["messaging", "queue", "jobs"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", - "symfony/framework-bundle": "^2.8|^3", + "symfony/framework-bundle": "^2.8|^3|^4", "enqueue/enqueue": "^0.8@dev", "enqueue/null": "^0.8@dev", "doctrine/orm": "~2.4" @@ -15,8 +16,8 @@ "phpunit/phpunit": "~5.5", "enqueue/test": "^0.8@dev", "doctrine/doctrine-bundle": "~1.2", - "symfony/browser-kit": "^2.8|^3", - "symfony/expression-language": "^2.8|^3" + "symfony/browser-kit": "^2.8|^3|^4", + "symfony/expression-language": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\JobQueue\\": "" }, diff --git a/pkg/null/Symfony/NullTransportFactory.php b/pkg/null/Symfony/NullTransportFactory.php index 2784405d0..7d70b8426 100644 --- a/pkg/null/Symfony/NullTransportFactory.php +++ b/pkg/null/Symfony/NullTransportFactory.php @@ -66,7 +66,9 @@ public function createContext(ContainerBuilder $container, array $config) $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); + $context = new Definition(NullContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $container->setDefinition($contextId, $context); @@ -80,6 +82,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(NullDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/null/composer.json b/pkg/null/composer.json index e24c54c2f..e100496ee 100644 --- a/pkg/null/composer.json +++ b/pkg/null/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Enqueue Null transport", "keywords": ["messaging", "queue", "testing"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -13,8 +14,8 @@ "enqueue/enqueue": "^0.8@dev", "enqueue/test": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Null\\": "" }, diff --git a/pkg/pheanstalk/composer.json b/pkg/pheanstalk/composer.json index 542e18ae5..a24699b49 100644 --- a/pkg/pheanstalk/composer.json +++ b/pkg/pheanstalk/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Queue Beanstalk transport", "keywords": ["messaging", "queue", "Pheanstalk", "Beanstalk"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -15,8 +16,8 @@ "enqueue/enqueue": "^0.8@dev", "enqueue/null": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Pheanstalk\\": "" }, diff --git a/pkg/rdkafka/RdKafkaTopic.php b/pkg/rdkafka/RdKafkaTopic.php index 9aea638ee..6faf12f8c 100644 --- a/pkg/rdkafka/RdKafkaTopic.php +++ b/pkg/rdkafka/RdKafkaTopic.php @@ -34,7 +34,6 @@ class RdKafkaTopic implements PsrTopic, PsrQueue public function __construct($name) { $this->name = $name; - $this->conf = new TopicConf(); } /** @@ -54,13 +53,21 @@ public function getQueueName() } /** - * @return TopicConf + * @return TopicConf|null */ public function getConf() { return $this->conf; } + /** + * @param TopicConf|null $conf + */ + public function setConf(TopicConf $conf = null) + { + $this->conf = $conf; + } + /** * @return int */ diff --git a/pkg/rdkafka/Tests/RdKafkaProducerTest.php b/pkg/rdkafka/Tests/RdKafkaProducerTest.php index 6ac08bbab..1c076e498 100644 --- a/pkg/rdkafka/Tests/RdKafkaProducerTest.php +++ b/pkg/rdkafka/Tests/RdKafkaProducerTest.php @@ -64,7 +64,7 @@ public function testShouldUseSerializerToEncodeMessageAndPutToExpectedTube() $kafkaProducer ->expects($this->once()) ->method('newTopic') - ->with('theQueueName', $this->isInstanceOf(TopicConf::class)) + ->with('theQueueName') ->willReturn($kafkaTopic) ; @@ -81,6 +81,74 @@ public function testShouldUseSerializerToEncodeMessageAndPutToExpectedTube() $producer->send(new RdKafkaTopic('theQueueName'), $message); } + public function testShouldPassNullAsTopicConfigIfNotSetOnTopic() + { + // guard + $kafkaTopic = $this->createKafkaTopicMock(); + $kafkaTopic + ->expects($this->once()) + ->method('produce') + ; + + $kafkaProducer = $this->createKafkaProducerMock(); + $kafkaProducer + ->expects($this->once()) + ->method('newTopic') + ->with('theQueueName', null) + ->willReturn($kafkaTopic) + ; + + $serializer = $this->createSerializerMock(); + $serializer + ->expects($this->once()) + ->method('toString') + ->willReturn('aSerializedMessage') + ; + + $producer = new RdKafkaProducer($kafkaProducer, $serializer); + + $topic = new RdKafkaTopic('theQueueName'); + + // guard + $this->assertNull($topic->getConf()); + + $producer->send($topic, new RdKafkaMessage()); + } + + public function testShouldPassCustomConfAsTopicConfigIfSetOnTopic() + { + $conf = new TopicConf(); + + // guard + $kafkaTopic = $this->createKafkaTopicMock(); + $kafkaTopic + ->expects($this->once()) + ->method('produce') + ; + + $kafkaProducer = $this->createKafkaProducerMock(); + $kafkaProducer + ->expects($this->once()) + ->method('newTopic') + ->with('theQueueName', $this->identicalTo($conf)) + ->willReturn($kafkaTopic) + ; + + $serializer = $this->createSerializerMock(); + $serializer + ->expects($this->once()) + ->method('toString') + ->willReturn('aSerializedMessage') + ; + + $producer = new RdKafkaProducer($kafkaProducer, $serializer); + + $topic = new RdKafkaTopic('theQueueName'); + $topic->setConf($conf); + + $producer->send($topic, new RdKafkaMessage()); + } + public function testShouldAllowGetPreviouslySetSerializer() { $producer = new RdKafkaProducer($this->createKafkaProducerMock(), $this->createSerializerMock()); diff --git a/pkg/rdkafka/Tests/RdKafkaTopicTest.php b/pkg/rdkafka/Tests/RdKafkaTopicTest.php index f81e4cd38..5ed22885a 100644 --- a/pkg/rdkafka/Tests/RdKafkaTopicTest.php +++ b/pkg/rdkafka/Tests/RdKafkaTopicTest.php @@ -27,10 +27,20 @@ public function testCouldSetGetKey() $this->assertSame('key', $topic->getKey()); } - public function testShouldReturnConfInstance() + public function testShouldReturnNullAsConfIfNotSet() { $topic = new RdKafkaTopic('topic'); - $this->assertInstanceOf(TopicConf::class, $topic->getConf()); + $this->assertNull($topic->getConf()); + } + + public function testShouldAllowGetPreviouslySetConf() + { + $topic = new RdKafkaTopic('topic'); + + $conf = new TopicConf(); + $topic->setConf($conf); + + $this->assertSame($conf, $topic->getConf()); } } diff --git a/pkg/rdkafka/composer.json b/pkg/rdkafka/composer.json index 1014002d1..45f87d769 100644 --- a/pkg/rdkafka/composer.json +++ b/pkg/rdkafka/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Queue Kafka Transport", "keywords": ["messaging", "queue", "kafka"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", diff --git a/pkg/redis/Symfony/RedisTransportFactory.php b/pkg/redis/Symfony/RedisTransportFactory.php index df4f462d9..5fcbe7603 100644 --- a/pkg/redis/Symfony/RedisTransportFactory.php +++ b/pkg/redis/Symfony/RedisTransportFactory.php @@ -90,6 +90,7 @@ public function createContext(ContainerBuilder $container, array $config) $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $context = new Definition(RedisContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -104,6 +105,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(RedisDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/redis/composer.json b/pkg/redis/composer.json index cb924e286..26f6dce96 100644 --- a/pkg/redis/composer.json +++ b/pkg/redis/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Queue Redis Transport", "keywords": ["messaging", "queue", "redis"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -15,8 +16,8 @@ "enqueue/enqueue": "^0.8@dev", "enqueue/null": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Redis\\": "" }, diff --git a/pkg/simple-client/SimpleClientContainerExtension.php b/pkg/simple-client/SimpleClientContainerExtension.php index f10a7b186..7bcb849cf 100644 --- a/pkg/simple-client/SimpleClientContainerExtension.php +++ b/pkg/simple-client/SimpleClientContainerExtension.php @@ -18,6 +18,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\NodeInterface; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Reference; @@ -79,6 +80,7 @@ public function load(array $configs, ContainerBuilder $container) ; $container->register('enqueue.client.config', Config::class) + ->setPublic(true) ->setArguments([ $config['client']['prefix'], $config['client']['app_name'], @@ -90,33 +92,38 @@ public function load(array $configs, ContainerBuilder $container) ]); $container->register('enqueue.client.rpc_factory', RpcFactory::class) + ->setPublic(true) ->setArguments([ new Reference('enqueue.transport.context'), ]); $container->register('enqueue.client.producer', Producer::class) + ->setPublic(true) ->setArguments([ new Reference('enqueue.client.driver'), new Reference('enqueue.client.rpc_factory'), ]); - $container->setAlias('enqueue.client.producer_v2', 'enqueue.client.producer'); + $container->setAlias('enqueue.client.producer_v2', new Alias('enqueue.client.producer', true)); $container->register('enqueue.client.meta.topic_meta_registry', TopicMetaRegistry::class) + ->setPublic(true) ->setArguments([[]]); $container->register('enqueue.client.meta.queue_meta_registry', QueueMetaRegistry::class) - ->setArguments([ - new Reference('enqueue.client.config'), - [], - ]); + ->setPublic(true) + ->setArguments([new Reference('enqueue.client.config'), []]); - $container->register('enqueue.client.processor_registry', ArrayProcessorRegistry::class); + $container->register('enqueue.client.processor_registry', ArrayProcessorRegistry::class) + ->setPublic(true) + ; $container->register('enqueue.client.delegate_processor', DelegateProcessor::class) + ->setPublic(true) ->setArguments([new Reference('enqueue.client.processor_registry')]); $container->register('enqueue.client.queue_consumer', QueueConsumer::class) + ->setPublic(true) ->setArguments([ new Reference('enqueue.transport.context'), new Reference('enqueue.consumption.extensions'), @@ -124,6 +131,7 @@ public function load(array $configs, ContainerBuilder $container) // router $container->register('enqueue.client.router_processor', RouterProcessor::class) + ->setPublic(true) ->setArguments([new Reference('enqueue.client.driver'), []]); $container->getDefinition('enqueue.client.processor_registry') ->addMethodCall('add', ['enqueue.client.router_processor', new Reference('enqueue.client.router_processor')]); @@ -134,6 +142,7 @@ public function load(array $configs, ContainerBuilder $container) $extensions = []; if ($config['client']['redelivered_delay_time']) { $container->register('enqueue.client.delay_redelivered_message_extension', DelayRedeliveredMessageExtension::class) + ->setPublic(true) ->setArguments([ new Reference('enqueue.client.driver'), $config['client']['redelivered_delay_time'], @@ -143,11 +152,13 @@ public function load(array $configs, ContainerBuilder $container) } $container->register('enqueue.client.extension.set_router_properties', SetRouterPropertiesExtension::class) + ->setPublic(true) ->setArguments([new Reference('enqueue.client.driver')]); $extensions[] = new Reference('enqueue.client.extension.set_router_properties'); $container->register('enqueue.consumption.extensions', ConsumptionChainExtension::class) + ->setPublic(true) ->setArguments([$extensions]); } diff --git a/pkg/simple-client/Tests/Functional/SimpleClientTest.php b/pkg/simple-client/Tests/Functional/SimpleClientTest.php index 3281aa274..cedbd11ff 100644 --- a/pkg/simple-client/Tests/Functional/SimpleClientTest.php +++ b/pkg/simple-client/Tests/Functional/SimpleClientTest.php @@ -22,7 +22,7 @@ class SimpleClientTest extends TestCase public function setUp() { - if (false == getenv('SYMFONY__RABBITMQ__HOST')) { + if (false == getenv('RABBITMQ_HOST')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } @@ -36,11 +36,11 @@ public function transportConfigDataProvider() 'default' => 'amqp', 'amqp' => [ 'driver' => 'ext', - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__AMQP__PORT'), - 'user' => getenv('SYMFONY__RABBITMQ__USER'), - 'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), ], ], ]]; @@ -65,11 +65,11 @@ public function transportConfigDataProvider() 'default' => 'rabbitmq_amqp', 'rabbitmq_amqp' => [ 'driver' => 'ext', - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__AMQP__PORT'), - 'user' => getenv('SYMFONY__RABBITMQ__USER'), - 'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), ], ], ]]; diff --git a/pkg/simple-client/composer.json b/pkg/simple-client/composer.json index 4f1c737ab..8a781d651 100644 --- a/pkg/simple-client/composer.json +++ b/pkg/simple-client/composer.json @@ -3,13 +3,14 @@ "type": "library", "description": "Message Queue Simple Client", "keywords": ["messaging", "queue", "amqp", "rabbitmq"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", "enqueue/enqueue": "^0.8@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3", - "symfony/console": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4", + "symfony/console": "^2.8|^3|^4" }, "require-dev": { "phpunit/phpunit": "~5.5", diff --git a/pkg/sqs/SqsContext.php b/pkg/sqs/SqsContext.php index 93bb2834d..57384daaf 100644 --- a/pkg/sqs/SqsContext.php +++ b/pkg/sqs/SqsContext.php @@ -186,12 +186,22 @@ public function deleteQueue(SqsDestination $dest) } /** + * @deprecated since 0.8 will be removed 0.9 use self::purgeQueue() + * * @param SqsDestination $dest */ public function purge(SqsDestination $dest) + { + $this->purgeQueue($dest); + } + + /** + * @param SqsDestination $destination + */ + public function purgeQueue(SqsDestination $destination) { $this->getClient()->purgeQueue([ - 'QueueUrl' => $this->getQueueUrl($dest), + 'QueueUrl' => $this->getQueueUrl($destination), ]); } } diff --git a/pkg/sqs/Symfony/SqsTransportFactory.php b/pkg/sqs/Symfony/SqsTransportFactory.php index c2ce2a304..e5f843a48 100644 --- a/pkg/sqs/Symfony/SqsTransportFactory.php +++ b/pkg/sqs/Symfony/SqsTransportFactory.php @@ -69,6 +69,7 @@ public function createContext(ContainerBuilder $container, array $config) $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $context = new Definition(SqsContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -83,6 +84,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(SqsDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/sqs/composer.json b/pkg/sqs/composer.json index c8e3a51c9..5965b56ff 100644 --- a/pkg/sqs/composer.json +++ b/pkg/sqs/composer.json @@ -3,6 +3,7 @@ "type": "library", "description": "Message Queue Amazon SQS Transport", "keywords": ["messaging", "queue", "amazon", "aws", "sqs"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", @@ -14,8 +15,8 @@ "enqueue/test": "^0.8@dev", "enqueue/enqueue": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Sqs\\": "" }, diff --git a/pkg/sqs/examples/consume.php b/pkg/sqs/examples/consume.php index a8914d165..a63f41fba 100644 --- a/pkg/sqs/examples/consume.php +++ b/pkg/sqs/examples/consume.php @@ -18,9 +18,9 @@ use Enqueue\Sqs\SqsConnectionFactory; $config = [ - 'key' => getenv('AWS__SQS__KEY'), - 'secret' => getenv('AWS__SQS__SECRET'), - 'region' => getenv('AWS__SQS__REGION'), + 'key' => getenv('AWS_SQS_KEY'), + 'secret' => getenv('AWS_SQS_SECRET'), + 'region' => getenv('AWS_SQS_REGION'), ]; $factory = new SqsConnectionFactory($config); diff --git a/pkg/sqs/examples/produce.php b/pkg/sqs/examples/produce.php index 878ba00a4..cb1a4d8e6 100644 --- a/pkg/sqs/examples/produce.php +++ b/pkg/sqs/examples/produce.php @@ -18,9 +18,9 @@ use Enqueue\Sqs\SqsConnectionFactory; $config = [ - 'key' => getenv('AWS__SQS__KEY'), - 'secret' => getenv('AWS__SQS__SECRET'), - 'region' => getenv('AWS__SQS__REGION'), + 'key' => getenv('AWS_SQS_KEY'), + 'secret' => getenv('AWS_SQS_SECRET'), + 'region' => getenv('AWS_SQS_REGION'), ]; $factory = new SqsConnectionFactory($config); diff --git a/pkg/stomp/StompConnectionFactory.php b/pkg/stomp/StompConnectionFactory.php index ce2aae733..1f82a7b8a 100644 --- a/pkg/stomp/StompConnectionFactory.php +++ b/pkg/stomp/StompConnectionFactory.php @@ -64,7 +64,7 @@ public function createContext() }); } - return new StompContext($this->stomp); + return new StompContext($this->establishConnection()); } /** diff --git a/pkg/stomp/Symfony/RabbitMqStompTransportFactory.php b/pkg/stomp/Symfony/RabbitMqStompTransportFactory.php index 48bbb719d..38b43b693 100644 --- a/pkg/stomp/Symfony/RabbitMqStompTransportFactory.php +++ b/pkg/stomp/Symfony/RabbitMqStompTransportFactory.php @@ -59,6 +59,7 @@ public function createDriver(ContainerBuilder $container, array $config) $container->setDefinition($managementId, $management); $driver = new Definition(RabbitMqStompDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/stomp/Symfony/StompTransportFactory.php b/pkg/stomp/Symfony/StompTransportFactory.php index 6144dd6d8..235752cdd 100644 --- a/pkg/stomp/Symfony/StompTransportFactory.php +++ b/pkg/stomp/Symfony/StompTransportFactory.php @@ -68,6 +68,7 @@ public function createContext(ContainerBuilder $container, array $config) $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $context = new Definition(StompContext::class); + $context->setPublic(true); $context->setFactory([new Reference($factoryId), 'createContext']); $contextId = sprintf('enqueue.transport.%s.context', $this->getName()); @@ -82,6 +83,7 @@ public function createContext(ContainerBuilder $container, array $config) public function createDriver(ContainerBuilder $container, array $config) { $driver = new Definition(StompDriver::class); + $driver->setPublic(true); $driver->setArguments([ new Reference(sprintf('enqueue.transport.%s.context', $this->getName())), new Reference('enqueue.client.config'), diff --git a/pkg/stomp/composer.json b/pkg/stomp/composer.json index 703cc9fe0..52f0ef57d 100644 --- a/pkg/stomp/composer.json +++ b/pkg/stomp/composer.json @@ -3,12 +3,14 @@ "type": "library", "description": "Message Queue Stomp Transport", "keywords": ["messaging", "queue", "stomp"], + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "require": { "php": ">=5.6", "stomp-php/stomp-php": "^4", "queue-interop/queue-interop": "^0.6@dev", "php-http/guzzle6-adapter": "^1.1", + "php-http/client-common": "^1.7@dev", "richardfullmer/rabbitmq-management-api": "^2.0" }, "require-dev": { @@ -17,8 +19,8 @@ "enqueue/enqueue": "^0.8@dev", "enqueue/null": "^0.8@dev", "queue-interop/queue-spec": "^0.5.3@dev", - "symfony/dependency-injection": "^2.8|^3", - "symfony/config": "^2.8|^3" + "symfony/dependency-injection": "^2.8|^3|^4", + "symfony/config": "^2.8|^3|^4" }, "autoload": { "psr-4": { "Enqueue\\Stomp\\": "" }, diff --git a/pkg/stomp/examples/consume.php b/pkg/stomp/examples/consume.php index 36d9e5a34..f6cc2fdff 100644 --- a/pkg/stomp/examples/consume.php +++ b/pkg/stomp/examples/consume.php @@ -19,11 +19,11 @@ use Stomp\Exception\ErrorFrameException; $config = [ - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'), - 'login' => getenv('SYMFONY__RABBITMQ__USER'), - 'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_STOMP_PORT'), + 'login' => getenv('RABBITMQ_USER'), + 'password' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), 'sync' => true, ]; diff --git a/pkg/stomp/examples/publish.php b/pkg/stomp/examples/publish.php index 47985885c..a320a40a6 100644 --- a/pkg/stomp/examples/publish.php +++ b/pkg/stomp/examples/publish.php @@ -19,11 +19,11 @@ use Stomp\Exception\ErrorFrameException; $config = [ - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'), - 'login' => getenv('SYMFONY__RABBITMQ__USER'), - 'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_STOMP_PORT'), + 'login' => getenv('RABBITMQ_USER'), + 'password' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), 'sync' => true, ]; diff --git a/pkg/test/RabbitmqAmqpExtension.php b/pkg/test/RabbitmqAmqpExtension.php index ad698fcfe..1a4da0e90 100644 --- a/pkg/test/RabbitmqAmqpExtension.php +++ b/pkg/test/RabbitmqAmqpExtension.php @@ -12,16 +12,16 @@ trait RabbitmqAmqpExtension */ private function buildAmqpContext() { - if (false == getenv('SYMFONY__RABBITMQ__HOST')) { + if (false == getenv('RABBITMQ_HOST')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } $config = [ - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__AMQP__PORT'), - 'user' => getenv('SYMFONY__RABBITMQ__USER'), - 'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), ]; return (new AmqpConnectionFactory($config))->createContext(); diff --git a/pkg/test/RabbitmqManagmentExtensionTrait.php b/pkg/test/RabbitmqManagmentExtensionTrait.php index b7c4a4440..660e20d58 100644 --- a/pkg/test/RabbitmqManagmentExtensionTrait.php +++ b/pkg/test/RabbitmqManagmentExtensionTrait.php @@ -9,10 +9,10 @@ trait RabbitmqManagmentExtensionTrait */ private function removeQueue($queueName) { - $rabbitmqHost = getenv('SYMFONY__RABBITMQ__HOST'); - $rabbitmqUser = getenv('SYMFONY__RABBITMQ__USER'); - $rabbitmqPassword = getenv('SYMFONY__RABBITMQ__PASSWORD'); - $rabbitmqVhost = getenv('SYMFONY__RABBITMQ__VHOST'); + $rabbitmqHost = getenv('RABBITMQ_HOST'); + $rabbitmqUser = getenv('RABBITMQ_USER'); + $rabbitmqPassword = getenv('RABBITMQ_PASSWORD'); + $rabbitmqVhost = getenv('RABBITMQ_VHOST'); $url = sprintf( 'http://%s:15672/api/queues/%s/%s', @@ -46,10 +46,10 @@ private function removeQueue($queueName) */ private function removeExchange($exchangeName) { - $rabbitmqHost = getenv('SYMFONY__RABBITMQ__HOST'); - $rabbitmqUser = getenv('SYMFONY__RABBITMQ__USER'); - $rabbitmqPassword = getenv('SYMFONY__RABBITMQ__PASSWORD'); - $rabbitmqVhost = getenv('SYMFONY__RABBITMQ__VHOST'); + $rabbitmqHost = getenv('RABBITMQ_HOST'); + $rabbitmqUser = getenv('RABBITMQ_USER'); + $rabbitmqPassword = getenv('RABBITMQ_PASSWORD'); + $rabbitmqVhost = getenv('RABBITMQ_VHOST'); $url = sprintf( 'http://%s:15672/api/exchanges/%s/%s', diff --git a/pkg/test/RabbitmqStompExtension.php b/pkg/test/RabbitmqStompExtension.php index ce3b80312..ae2bf4bda 100644 --- a/pkg/test/RabbitmqStompExtension.php +++ b/pkg/test/RabbitmqStompExtension.php @@ -12,16 +12,16 @@ trait RabbitmqStompExtension */ private function buildStompContext() { - if (false == getenv('SYMFONY__RABBITMQ__HOST')) { + if (false == getenv('RABBITMQ_HOST')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } $config = [ - 'host' => getenv('SYMFONY__RABBITMQ__HOST'), - 'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'), - 'login' => getenv('SYMFONY__RABBITMQ__USER'), - 'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'), - 'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'), + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_STOMP_PORT'), + 'login' => getenv('RABBITMQ_USER'), + 'password' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), 'sync' => true, ]; diff --git a/pkg/test/RedisExtension.php b/pkg/test/RedisExtension.php index 9b98c5443..0740c8f21 100644 --- a/pkg/test/RedisExtension.php +++ b/pkg/test/RedisExtension.php @@ -12,13 +12,13 @@ trait RedisExtension */ private function buildPhpRedisContext() { - if (false == getenv('SYMFONY__REDIS__HOST')) { + if (false == getenv('REDIS_HOST')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } $config = [ - 'host' => getenv('SYMFONY__REDIS__HOST'), - 'port' => getenv('SYMFONY__REDIS__PORT'), + 'host' => getenv('REDIS_HOST'), + 'port' => getenv('REDIS_PORT'), 'vendor' => 'phpredis', 'lazy' => false, ]; @@ -31,13 +31,13 @@ private function buildPhpRedisContext() */ private function buildPRedisContext() { - if (false == getenv('SYMFONY__REDIS__HOST')) { + if (false == getenv('REDIS_HOST')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } $config = [ - 'host' => getenv('SYMFONY__REDIS__HOST'), - 'port' => getenv('SYMFONY__REDIS__PORT'), + 'host' => getenv('REDIS_HOST'), + 'port' => getenv('REDIS_PORT'), 'vendor' => 'predis', 'lazy' => false, ]; diff --git a/pkg/test/SqsExtension.php b/pkg/test/SqsExtension.php index 530b0e988..4446c3346 100644 --- a/pkg/test/SqsExtension.php +++ b/pkg/test/SqsExtension.php @@ -12,14 +12,14 @@ trait SqsExtension */ private function buildSqsContext() { - if (false == getenv('AWS__SQS__KEY')) { + if (false == getenv('AWS_SQS_KEY')) { throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment'); } $config = [ - 'key' => getenv('AWS__SQS__KEY'), - 'secret' => getenv('AWS__SQS__SECRET'), - 'region' => getenv('AWS__SQS__REGION'), + 'key' => getenv('AWS_SQS_KEY'), + 'secret' => getenv('AWS_SQS_SECRET'), + 'region' => getenv('AWS_SQS_REGION'), 'lazy' => false, ]; diff --git a/pkg/test/composer.json b/pkg/test/composer.json index 8d25ea853..06a34951d 100644 --- a/pkg/test/composer.json +++ b/pkg/test/composer.json @@ -1,5 +1,6 @@ { "name": "enqueue/test", + "homepage": "https://github.com/php-enqueue/enqueue-dev", "license": "MIT", "autoload": { "psr-4": { "Enqueue\\Test\\": "" }