diff --git a/composer.json b/composer.json index 639b274b6..7fdbc11b9 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ "ext-mongodb": "^1.3", "ext-rdkafka": "^3.0.3", - "queue-interop/amqp-interop": "^0.8", - "queue-interop/queue-interop": "^0.7|^0.8", + "queue-interop/amqp-interop": "dev-master", + "queue-interop/queue-interop": "dev-master", "bunny/bunny": "^0.2.4|^0.3|^0.4", "php-amqplib/php-amqplib": "^2.7", "doctrine/dbal": "^2.6", @@ -55,6 +55,16 @@ "kwn/php-rdkafka-stubs": "^1.0.2", "friendsofphp/php-cs-fixer": "^2" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/Sevavietl/queue-interop" + }, + { + "type": "vcs", + "url": "https://github.com/Sevavietl/amqp-interop" + } + ], "autoload": { "psr-4": { "Enqueue\\AmqpBunny\\": "pkg/amqp-bunny/", diff --git a/pkg/amqp-bunny/AmqpContext.php b/pkg/amqp-bunny/AmqpContext.php index f57554335..552a251d7 100644 --- a/pkg/amqp-bunny/AmqpContext.php +++ b/pkg/amqp-bunny/AmqpContext.php @@ -71,9 +71,11 @@ public function __construct($bunnyChannel, array $config) } /** + * @param mixed $body + * * @return InteropAmqpMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new AmqpMessage($body, $properties, $headers); } diff --git a/pkg/amqp-ext/AmqpContext.php b/pkg/amqp-ext/AmqpContext.php index 5ea099da2..16e324c28 100644 --- a/pkg/amqp-ext/AmqpContext.php +++ b/pkg/amqp-ext/AmqpContext.php @@ -54,9 +54,11 @@ public function __construct($extChannel) } /** + * @param mixed $body + * * @return InteropAmqpMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new AmqpMessage($body, $properties, $headers); } diff --git a/pkg/amqp-lib/AmqpContext.php b/pkg/amqp-lib/AmqpContext.php index 83167c3db..f43153b16 100644 --- a/pkg/amqp-lib/AmqpContext.php +++ b/pkg/amqp-lib/AmqpContext.php @@ -60,9 +60,11 @@ public function __construct(AbstractConnection $connection, array $config) } /** + * @param mixed $body + * * @return InteropAmqpMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new AmqpMessage($body, $properties, $headers); } diff --git a/pkg/dbal/DbalContext.php b/pkg/dbal/DbalContext.php index f6119481c..2d176f51e 100644 --- a/pkg/dbal/DbalContext.php +++ b/pkg/dbal/DbalContext.php @@ -64,7 +64,7 @@ public function __construct($connection, array $config = []) /** * {@inheritdoc} */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { $message = new DbalMessage(); $message->setBody($body); diff --git a/pkg/dbal/DbalMessage.php b/pkg/dbal/DbalMessage.php index af62c1079..318542274 100644 --- a/pkg/dbal/DbalMessage.php +++ b/pkg/dbal/DbalMessage.php @@ -4,14 +4,12 @@ namespace Enqueue\Dbal; +use Interop\Queue\Impl\StringBodyOnlyTrait; use Interop\Queue\Message; class DbalMessage implements Message { - /** - * @var string - */ - private $body; + use StringBodyOnlyTrait; /** * @var array @@ -84,16 +82,6 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redeliverAfter = null; } - public function setBody(string $body): void - { - $this->body = $body; - } - - public function getBody(): string - { - return $this->body; - } - public function setProperties(array $properties): void { $this->properties = $properties; diff --git a/pkg/dbal/DbalProducer.php b/pkg/dbal/DbalProducer.php index 5435629eb..c31bd0e91 100644 --- a/pkg/dbal/DbalProducer.php +++ b/pkg/dbal/DbalProducer.php @@ -62,8 +62,6 @@ public function send(Destination $destination, Message $message): void $message->setTimeToLive($this->timeToLive); } - $body = $message->getBody(); - $publishedAt = null !== $message->getPublishedAt() ? $message->getPublishedAt() : (int) (microtime(true) * 10000) @@ -72,7 +70,7 @@ public function send(Destination $destination, Message $message): void $dbalMessage = [ 'id' => Uuid::uuid4(), 'published_at' => $publishedAt, - 'body' => $body, + 'body' => $message->getBody(), 'headers' => JSON::encode($message->getHeaders()), 'properties' => JSON::encode($message->getProperties()), 'priority' => -1 * $message->getPriority(), diff --git a/pkg/dbal/Tests/DbalConsumerTest.php b/pkg/dbal/Tests/DbalConsumerTest.php index c042c5c86..b46e15f50 100644 --- a/pkg/dbal/Tests/DbalConsumerTest.php +++ b/pkg/dbal/Tests/DbalConsumerTest.php @@ -217,11 +217,11 @@ private function createConectionMock() class InvalidMessage implements Message { - public function getBody(): string + public function getBody() { } - public function setBody(string $body): void + public function setBody($body): void { } diff --git a/pkg/fs/FsContext.php b/pkg/fs/FsContext.php index 480074e03..f09b0b50f 100644 --- a/pkg/fs/FsContext.php +++ b/pkg/fs/FsContext.php @@ -58,9 +58,11 @@ public function __construct(string $storeDir, int $preFetchCount, int $chmod, in } /** + * @param mixed $body + * * @return FsMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new FsMessage($body, $properties, $headers); } diff --git a/pkg/fs/FsMessage.php b/pkg/fs/FsMessage.php index d66ee52cd..f99879416 100644 --- a/pkg/fs/FsMessage.php +++ b/pkg/fs/FsMessage.php @@ -9,7 +9,7 @@ class FsMessage implements Message, \JsonSerializable { /** - * @var string + * @var string|int|float|array|\JsonSerializable */ private $body; @@ -28,7 +28,7 @@ class FsMessage implements Message, \JsonSerializable */ private $redelivered; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -36,12 +36,12 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } - public function getBody(): string + public function getBody() { return $this->body; } diff --git a/pkg/gearman/GearmanContext.php b/pkg/gearman/GearmanContext.php index 80a93882e..3e8df8347 100644 --- a/pkg/gearman/GearmanContext.php +++ b/pkg/gearman/GearmanContext.php @@ -40,9 +40,11 @@ public function __construct(array $config) } /** + * @param mixed $body + * * @return GearmanMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new GearmanMessage($body, $properties, $headers); } diff --git a/pkg/gearman/GearmanMessage.php b/pkg/gearman/GearmanMessage.php index 625566d62..4dc5e9ba2 100644 --- a/pkg/gearman/GearmanMessage.php +++ b/pkg/gearman/GearmanMessage.php @@ -9,7 +9,7 @@ class GearmanMessage implements Message, \JsonSerializable { /** - * @var string + * @var string|int|float|array|\JsonSerializable */ private $body; @@ -33,7 +33,7 @@ class GearmanMessage implements Message, \JsonSerializable */ private $job; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -41,12 +41,12 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } - public function getBody(): string + public function getBody() { return $this->body; } diff --git a/pkg/gps/GpsContext.php b/pkg/gps/GpsContext.php index 77e6200cf..6a9081c5e 100644 --- a/pkg/gps/GpsContext.php +++ b/pkg/gps/GpsContext.php @@ -61,9 +61,11 @@ public function __construct($client, array $options = []) } /** + * @param mixed $body + * * @return GpsMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new GpsMessage($body, $properties, $headers); } diff --git a/pkg/gps/GpsMessage.php b/pkg/gps/GpsMessage.php index 5e83e078c..215e67178 100644 --- a/pkg/gps/GpsMessage.php +++ b/pkg/gps/GpsMessage.php @@ -10,7 +10,7 @@ class GpsMessage implements Message, \JsonSerializable { /** - * @var string + * @var string|int|float|array|\JsonSerializable */ private $body; @@ -34,7 +34,7 @@ class GpsMessage implements Message, \JsonSerializable */ private $nativeMessage; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -43,12 +43,12 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function getBody(): string + public function getBody() { return $this->body; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } diff --git a/pkg/mongodb/MongodbContext.php b/pkg/mongodb/MongodbContext.php index e6f5a579c..af33abf81 100644 --- a/pkg/mongodb/MongodbContext.php +++ b/pkg/mongodb/MongodbContext.php @@ -41,9 +41,11 @@ public function __construct($client, array $config = []) } /** + * @param mixed $body + * * @return MongodbMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { $message = new MongodbMessage(); $message->setBody($body); diff --git a/pkg/mongodb/MongodbMessage.php b/pkg/mongodb/MongodbMessage.php index fbfbd75d6..6da34b740 100644 --- a/pkg/mongodb/MongodbMessage.php +++ b/pkg/mongodb/MongodbMessage.php @@ -4,19 +4,17 @@ namespace Enqueue\Mongodb; +use Interop\Queue\Impl\StringBodyOnlyTrait; use Interop\Queue\Message; class MongodbMessage implements Message { - /** - * @var string - */ - private $id; + use StringBodyOnlyTrait; /** * @var string */ - private $body; + private $id; /** * @var array @@ -75,16 +73,6 @@ public function getId(): ?string return $this->id; } - public function setBody(string $body): void - { - $this->body = $body; - } - - public function getBody(): string - { - return $this->body; - } - public function setProperties(array $properties): void { $this->properties = $properties; diff --git a/pkg/mongodb/MongodbProducer.php b/pkg/mongodb/MongodbProducer.php index d27f014eb..4a5e9f5d9 100644 --- a/pkg/mongodb/MongodbProducer.php +++ b/pkg/mongodb/MongodbProducer.php @@ -57,8 +57,6 @@ public function send(Destination $destination, Message $message): void $message->setTimeToLive($this->timeToLive); } - $body = $message->getBody(); - $publishedAt = null !== $message->getPublishedAt() ? $message->getPublishedAt() : (int) (microtime(true) * 10000) @@ -66,7 +64,7 @@ public function send(Destination $destination, Message $message): void $mongoMessage = [ 'published_at' => $publishedAt, - 'body' => $body, + 'body' => $message->getBody(), 'headers' => JSON::encode($message->getHeaders()), 'properties' => JSON::encode($message->getProperties()), 'priority' => $message->getPriority(), diff --git a/pkg/mongodb/Tests/MongodbConsumerTest.php b/pkg/mongodb/Tests/MongodbConsumerTest.php index e41681256..d11c4e94e 100644 --- a/pkg/mongodb/Tests/MongodbConsumerTest.php +++ b/pkg/mongodb/Tests/MongodbConsumerTest.php @@ -131,11 +131,11 @@ private function createContextMock() class InvalidMessage implements Message { - public function getBody(): string + public function getBody() { } - public function setBody(string $body): void + public function setBody($body): void { } diff --git a/pkg/null/NullContext.php b/pkg/null/NullContext.php index 5f6001cab..93965395a 100644 --- a/pkg/null/NullContext.php +++ b/pkg/null/NullContext.php @@ -16,9 +16,11 @@ class NullContext implements Context { /** + * @param mixed $body + * * @return NullMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { $message = new NullMessage(); $message->setBody($body); diff --git a/pkg/null/NullMessage.php b/pkg/null/NullMessage.php index bd48a387e..b733a2d83 100644 --- a/pkg/null/NullMessage.php +++ b/pkg/null/NullMessage.php @@ -37,7 +37,7 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } diff --git a/pkg/pheanstalk/PheanstalkContext.php b/pkg/pheanstalk/PheanstalkContext.php index 3e2fe834d..2de406619 100644 --- a/pkg/pheanstalk/PheanstalkContext.php +++ b/pkg/pheanstalk/PheanstalkContext.php @@ -31,9 +31,11 @@ public function __construct(Pheanstalk $pheanstalk) } /** + * @param mixed $body + * * @return PheanstalkMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new PheanstalkMessage($body, $properties, $headers); } diff --git a/pkg/pheanstalk/PheanstalkMessage.php b/pkg/pheanstalk/PheanstalkMessage.php index cf4ea1905..995018ad5 100644 --- a/pkg/pheanstalk/PheanstalkMessage.php +++ b/pkg/pheanstalk/PheanstalkMessage.php @@ -35,7 +35,7 @@ class PheanstalkMessage implements Message, \JsonSerializable */ private $job; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -43,7 +43,7 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } diff --git a/pkg/rdkafka/RdKafkaContext.php b/pkg/rdkafka/RdKafkaContext.php index 22d4a8e47..6e99a1207 100644 --- a/pkg/rdkafka/RdKafkaContext.php +++ b/pkg/rdkafka/RdKafkaContext.php @@ -57,9 +57,11 @@ public function __construct(array $config) } /** + * @param mixed $body + * * @return RdKafkaMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new RdKafkaMessage($body, $properties, $headers); } diff --git a/pkg/rdkafka/RdKafkaMessage.php b/pkg/rdkafka/RdKafkaMessage.php index 0785a5644..6d89b4743 100644 --- a/pkg/rdkafka/RdKafkaMessage.php +++ b/pkg/rdkafka/RdKafkaMessage.php @@ -10,7 +10,7 @@ class RdKafkaMessage implements Message { /** - * @var string + * @var mixed */ private $body; @@ -44,7 +44,7 @@ class RdKafkaMessage implements Message */ private $kafkaMessage; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -52,12 +52,12 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } - public function getBody(): string + public function getBody() { return $this->body; } diff --git a/pkg/redis/RedisContext.php b/pkg/redis/RedisContext.php index 344bb20c5..9c974ebdb 100644 --- a/pkg/redis/RedisContext.php +++ b/pkg/redis/RedisContext.php @@ -59,9 +59,11 @@ public function __construct($redis, int $redeliveryDelay) } /** + * @param mixed $body + * * @return RedisMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new RedisMessage($body, $properties, $headers); } diff --git a/pkg/redis/RedisMessage.php b/pkg/redis/RedisMessage.php index 74c65475a..0a8a2415c 100644 --- a/pkg/redis/RedisMessage.php +++ b/pkg/redis/RedisMessage.php @@ -9,7 +9,7 @@ class RedisMessage implements Message { /** - * @var string + * @var mixed */ private $body; @@ -38,7 +38,7 @@ class RedisMessage implements Message */ private $key; - public function __construct(string $body = '', array $properties = [], array $headers = []) + public function __construct($body = '', array $properties = [], array $headers = []) { $this->body = $body; $this->properties = $properties; @@ -47,12 +47,12 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function getBody(): string + public function getBody() { return $this->body; } - public function setBody(string $body): void + public function setBody($body): void { $this->body = $body; } diff --git a/pkg/sns/SnsContext.php b/pkg/sns/SnsContext.php index b489f8d57..c29d7ebe0 100644 --- a/pkg/sns/SnsContext.php +++ b/pkg/sns/SnsContext.php @@ -40,9 +40,11 @@ public function __construct(SnsClient $client, array $config) } /** + * @param mixed $body + * * @return SnsMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new SnsMessage($body, $properties, $headers); } diff --git a/pkg/snsqs/SnsQsContext.php b/pkg/snsqs/SnsQsContext.php index d520cdb10..c40b2e46d 100644 --- a/pkg/snsqs/SnsQsContext.php +++ b/pkg/snsqs/SnsQsContext.php @@ -74,9 +74,11 @@ public function __construct($snsContext, $sqsContext) } /** + * @param mixed $body + * * @return SnsQsMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new SnsQsMessage($body, $properties, $headers); } diff --git a/pkg/sqs/SqsContext.php b/pkg/sqs/SqsContext.php index 60906f72f..39c1c1e7a 100644 --- a/pkg/sqs/SqsContext.php +++ b/pkg/sqs/SqsContext.php @@ -49,9 +49,11 @@ public function __construct(SqsClient $client, array $config) } /** + * @param mixed $body + * * @return SqsMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new SqsMessage($body, $properties, $headers); } diff --git a/pkg/sqs/SqsMessage.php b/pkg/sqs/SqsMessage.php index 1d9d26bec..0b6c4e533 100644 --- a/pkg/sqs/SqsMessage.php +++ b/pkg/sqs/SqsMessage.php @@ -4,14 +4,12 @@ namespace Enqueue\Sqs; +use Interop\Queue\Impl\StringBodyOnlyTrait; use Interop\Queue\Message; class SqsMessage implements Message { - /** - * @var string - */ - private $body; + use StringBodyOnlyTrait; /** * @var array @@ -57,16 +55,6 @@ public function __construct(string $body = '', array $properties = [], array $he $this->delaySeconds = 0; } - public function setBody(string $body): void - { - $this->body = $body; - } - - public function getBody(): string - { - return $this->body; - } - public function setProperties(array $properties): void { $this->properties = $properties; diff --git a/pkg/stomp/StompContext.php b/pkg/stomp/StompContext.php index e03b11cb6..7819f827b 100644 --- a/pkg/stomp/StompContext.php +++ b/pkg/stomp/StompContext.php @@ -43,9 +43,11 @@ public function __construct($stomp) } /** + * @param mixed $body + * * @return StompMessage */ - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new StompMessage($body, $properties, $headers); } diff --git a/pkg/stomp/StompMessage.php b/pkg/stomp/StompMessage.php index bb563c8cd..0de6ba262 100644 --- a/pkg/stomp/StompMessage.php +++ b/pkg/stomp/StompMessage.php @@ -4,15 +4,13 @@ namespace Enqueue\Stomp; +use Interop\Queue\Impl\StringBodyOnlyTrait; use Interop\Queue\Message; use Stomp\Transport\Frame; class StompMessage implements Message { - /** - * @var string - */ - private $body; + use StringBodyOnlyTrait; /** * @var array @@ -42,16 +40,6 @@ public function __construct(string $body = '', array $properties = [], array $he $this->redelivered = false; } - public function setBody(string $body): void - { - $this->body = $body; - } - - public function getBody(): string - { - return $this->body; - } - public function setProperties(array $properties): void { $this->properties = $properties; diff --git a/pkg/wamp/WampContext.php b/pkg/wamp/WampContext.php index 9bbed5087..8b28c249e 100644 --- a/pkg/wamp/WampContext.php +++ b/pkg/wamp/WampContext.php @@ -38,7 +38,7 @@ public function __construct(callable $clientFactory) $this->setSerializer(new JsonSerializer()); } - public function createMessage(string $body = '', array $properties = [], array $headers = []): Message + public function createMessage($body = '', array $properties = [], array $headers = []): Message { return new WampMessage($body, $properties, $headers); }