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. 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 9310790..bdc59c3 100644 --- a/tests/TypesTest.php +++ b/tests/TypesTest.php @@ -48,6 +48,7 @@ public function testMessageType() { 'id', 'clientId', 'connectionId', + 'connectionKey', 'name', 'data', 'encoding',