From 18c39445f582568958f5593b8eb036f94306be4f Mon Sep 17 00:00:00 2001 From: blade Date: Tue, 2 Aug 2016 09:19:25 +0200 Subject: [PATCH 1/2] Added connectionKey to Message to allow delegated publishing Fixed license in composer.json --- composer.json | 2 +- src/Models/Message.php | 14 ++++++++++++-- tests/ChannelMessagesTest.php | 17 +++++++++++++++++ tests/TypesTest.php | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 3a4cee7..c2cb39d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require-dev": { "phpunit/phpunit": ">=4.5" }, - "license": "MIT", + "license": "Apache-2.0", "authors": [ { "name": "Ably", diff --git a/src/Models/Message.php b/src/Models/Message.php index f1a57b2..d73d1aa 100644 --- a/src/Models/Message.php +++ b/src/Models/Message.php @@ -7,14 +7,24 @@ class Message extends BaseMessage { * @var string|null The event name of the message. */ public $name; + + /** + * @var string|null Connection key from a realtime connection, + * when publishing on behalf of it. + */ + public $connectionKey; protected function encode() { $msg = parent::encode(); if ( isset( $this->name ) && $this->name ) { - $msg->name = $this->name; + $msg->name = $this->name; + } + + if ( isset( $this->connectionKey ) && $this->connectionKey ) { + $msg->connectionKey = $this->connectionKey; } return $msg; } -} \ No newline at end of file +} diff --git a/tests/ChannelMessagesTest.php b/tests/ChannelMessagesTest.php index f550168..790751e 100644 --- a/tests/ChannelMessagesTest.php +++ b/tests/ChannelMessagesTest.php @@ -259,6 +259,23 @@ public function testTooLargeMessage() { $channel->publish( $msg ); } + /** + * Verify that publishing on behalf of realtime clients works + */ + public function testPublishConnectionKey() { + $channel = self::$ably->channel( 'connKey' ); + + + $msg = new Message(); + $msg->name = 'delegatedMsg'; + $msg->data = 'test payload'; + $msg->connectionKey = 'fake!realtime_key'; + + // publishing the message with an invalid key must fail + $this->setExpectedException( 'Ably\Exceptions\AblyException', '', 40006 ); + $channel->publish( $msg ); + } + /** * Encryption mismatch - publish message over encrypted channel, retrieve history over unencrypted channel */ diff --git a/tests/TypesTest.php b/tests/TypesTest.php index c1144cb..d55b468 100644 --- a/tests/TypesTest.php +++ b/tests/TypesTest.php @@ -48,6 +48,7 @@ public function testMessageType() { 'id', 'clientId', 'connectionId', + 'connectionKey', 'name', 'data', 'encoding', From 7a25ecea5eecadc5eb1fa0836b72fe7c30f2732c Mon Sep 17 00:00:00 2001 From: blade Date: Tue, 2 Aug 2016 09:40:40 +0200 Subject: [PATCH 2/2] Updated README --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 502fce3..5a4e896 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ Install Ably from the shell with: $ composer require ably/ably-php --update-no-dev -Omit the `--update-no-dev` parameter, if you want to run tests. Then simply require composer's autoloader: +Then simply require composer's autoloader: ```php -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/vendor/autoload.php'; ``` ### Manual installation @@ -111,6 +111,10 @@ $statsPage->next(); // retrieves the next page => \Ably\Models\PaginatedResult $client->time(); // in milliseconds => 1430313364993 ``` +## Laravel + +If you're using Laravel, you may want to check out [ably-php-laravel](https://packagist.org/packages/ably/ably-php-laravel) wrapper, which is a wrapper with Laravel-specific helper classes. + ## Support, feedback and troubleshooting Please visit http://support.ably.io/ for access to our knowledgebase and to ask for any assistance.