Skip to content

Commit e402b83

Browse files
author
Jon Elverkilde
authored
Merge pull request pusher#297 from pusher/fix_interface
Use type hints, document Guzzle Exception
2 parents 1a5d9d7 + 319cebd commit e402b83

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 6.0.1
4+
5+
* [CHANGED] Use type hints where possible (mixed type not available in PHP7).
6+
* [CHANGED] Document that functions can throw GuzzleException.
7+
38
## 6.0.0
49

510
* [CHANGED] internal HTTP client to Guzzle

src/Pusher.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface
1414
/**
1515
* @var string Version
1616
*/
17-
public static $VERSION = '6.0.0';
17+
public static $VERSION = '6.0.1';
1818

1919
/**
2020
* @var null|PusherCrypto
@@ -337,10 +337,10 @@ public static function array_implode($glue, $separator, $array)
337337
*
338338
* @throws PusherException Throws PusherException if $channels is an array of size 101 or above or $socket_id is invalid
339339
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
340+
* @throws GuzzleException
340341
*
341-
* @return object
342342
*/
343-
public function trigger($channels, $event, $data, $params = array(), $already_encoded = false)
343+
public function trigger($channels, $event, $data, $params = array(), $already_encoded = false) : object
344344
{
345345
if (is_string($channels) === true) {
346346
$channels = array($channels);
@@ -431,10 +431,10 @@ public function trigger($channels, $event, $data, $params = array(), $already_en
431431
* @param bool $already_encoded [optional]
432432
*
433433
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
434+
* @throws GuzzleException
434435
*
435-
* @return object
436436
*/
437-
public function triggerBatch($batch = array(), $already_encoded = false)
437+
public function triggerBatch($batch = array(), $already_encoded = false) : object
438438
{
439439
foreach ($batch as $key => $event) {
440440
$this->validate_channel($event['channel']);
@@ -497,10 +497,10 @@ public function triggerBatch($batch = array(), $already_encoded = false)
497497
*
498498
* @throws PusherException If $channel is invalid
499499
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
500+
* @throws GuzzleException
500501
*
501-
* @return object
502502
*/
503-
public function get_channel_info($channel, $params = array())
503+
public function get_channel_info($channel, $params = array()) : object
504504
{
505505
$this->validate_channel($channel);
506506

@@ -513,10 +513,10 @@ public function get_channel_info($channel, $params = array())
513513
* @param array $params Additional parameters for the query e.g. $params = array( 'info' => 'connection_count' )
514514
*
515515
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
516+
* @throws GuzzleException
516517
*
517-
* @return object
518518
*/
519-
public function get_channels($params = array())
519+
public function get_channels($params = array()) : object
520520
{
521521
$result = $this->get('/channels', $params);
522522

@@ -531,10 +531,10 @@ public function get_channels($params = array())
531531
* @param string $channel The name of the channel
532532
*
533533
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
534+
* @throws GuzzleException
534535
*
535-
* @return object
536536
*/
537-
public function get_users_info($channel)
537+
public function get_users_info($channel) : object
538538
{
539539
return $this->get('/channels/'.$channel.'/users');
540540
}
@@ -548,6 +548,7 @@ public function get_users_info($channel)
548548
* @param bool $associative When true, return the response body as an associative array, else return as an object
549549
*
550550
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
551+
* @throws GuzzleException
551552
*
552553
* @return mixed See Pusher API docs
553554
*/
@@ -590,7 +591,7 @@ public function get($path, $params = array(), $associative = false)
590591
*
591592
* @return string Json encoded authentication string.
592593
*/
593-
public function socket_auth($channel, $socket_id, $custom_data = null)
594+
public function socket_auth($channel, $socket_id, $custom_data = null) : string
594595
{
595596
$this->validate_channel($channel);
596597
$this->validate_socket_id($socket_id);
@@ -628,9 +629,8 @@ public function socket_auth($channel, $socket_id, $custom_data = null)
628629
*
629630
* @throws PusherException Throws exception if $channel is invalid or above or $socket_id is invalid
630631
*
631-
* @return string
632632
*/
633-
public function presence_auth($channel, $socket_id, $user_id, $user_info = null)
633+
public function presence_auth($channel, $socket_id, $user_id, $user_info = null) : string
634634
{
635635
$user_data = array('user_id' => $user_id);
636636
if ($user_info) {
@@ -650,7 +650,7 @@ public function presence_auth($channel, $socket_id, $user_id, $user_info = null)
650650
*
651651
* @return Webhook marshalled object with the properties time_ms (an int) and events (an array of event objects)
652652
*/
653-
public function webhook($headers, $body)
653+
public function webhook($headers, $body) : object
654654
{
655655
$this->ensure_valid_signature($headers, $body);
656656

src/PusherInterface.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function getSettings();
2323
*
2424
* @throws PusherException Throws exception if $channels is an array of size 101 or above or $socket_id is invalid
2525
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
26+
* @throws GuzzleException
2627
*
27-
* @return object
2828
*/
29-
public function trigger($channels, $event, $data, $socket_id = null, $already_encoded = false);
29+
public function trigger($channels, $event, $data, $socket_id = null, $already_encoded = false) : object;
3030

3131
/**
3232
* Trigger multiple events at the same time.
@@ -36,10 +36,10 @@ public function trigger($channels, $event, $data, $socket_id = null, $already_en
3636
*
3737
* @throws PusherException Throws exception if curl wasn't initialized correctly
3838
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
39+
* @throws GuzzleException
3940
*
40-
* @return object
4141
*/
42-
public function triggerBatch($batch = array(), $already_encoded = false);
42+
public function triggerBatch($batch = array(), $already_encoded = false) : object;
4343

4444
/**
4545
* Fetch channel information for a specific channel.
@@ -49,10 +49,10 @@ public function triggerBatch($batch = array(), $already_encoded = false);
4949
*
5050
* @throws PusherException If $channel is invalid or if curl wasn't initialized correctly
5151
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
52+
* @throws GuzzleException
5253
*
53-
* @return object
5454
*/
55-
public function get_channel_info($channel, $params = array());
55+
public function get_channel_info($channel, $params = array()) : object;
5656

5757
/**
5858
* Fetch a list containing all channels.
@@ -61,10 +61,10 @@ public function get_channel_info($channel, $params = array());
6161
*
6262
* @throws PusherException Throws exception if curl wasn't initialized correctly
6363
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
64+
* @throws GuzzleException
6465
*
65-
* @return object
6666
*/
67-
public function get_channels($params = array());
67+
public function get_channels($params = array()) : object;
6868

6969
/**
7070
* Fetch user ids currently subscribed to a presence channel.
@@ -73,10 +73,10 @@ public function get_channels($params = array());
7373
*
7474
* @throws PusherException Throws exception if curl wasn't initialized correctly
7575
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
76+
* @throws GuzzleException
7677
*
77-
* @return object
7878
*/
79-
public function get_users_info($channel);
79+
public function get_users_info($channel) : object;
8080

8181
/**
8282
* GET arbitrary REST API resource using a synchronous http client.
@@ -88,6 +88,7 @@ public function get_users_info($channel);
8888
*
8989
* @throws PusherException Throws exception if curl wasn't initialized correctly
9090
* @throws ApiErrorException Throws ApiErrorException if the Channels HTTP API responds with an error
91+
* @throws GuzzleException
9192
*
9293
* @return mixed See Pusher API docs
9394
*/
@@ -104,7 +105,7 @@ public function get($path, $params = array());
104105
*
105106
* @return string Json encoded authentication string.
106107
*/
107-
public function socket_auth($channel, $socket_id, $custom_data = null);
108+
public function socket_auth($channel, $socket_id, $custom_data = null) : string;
108109

109110
/**
110111
* Creates a presence signature (an extension of socket signing).
@@ -116,12 +117,12 @@ public function socket_auth($channel, $socket_id, $custom_data = null);
116117
*
117118
* @throws PusherException Throws exception if $channel is invalid or above or $socket_id is invalid
118119
*
119-
* @return string
120120
*/
121-
public function presence_auth($channel, $socket_id, $user_id, $user_info = null);
121+
public function presence_auth($channel, $socket_id, $user_id, $user_info = null) : string;
122122

123123
/**
124-
* Verify that a webhook actually came from Pusher, decrypts any encrypted events, and marshals them into a PHP object.
124+
* Verify that a webhook actually came from Pusher, decrypts any
125+
* encrypted events, and marshals them into a PHP object.
125126
*
126127
* @param array $headers a array of headers from the request (for example, from getallheaders())
127128
* @param string $body the body of the request (for example, from file_get_contents('php://input'))
@@ -130,7 +131,7 @@ public function presence_auth($channel, $socket_id, $user_id, $user_info = null)
130131
*
131132
* @return Webhook marshalled object with the properties time_ms (an int) and events (an array of event objects)
132133
*/
133-
public function webhook($headers, $body);
134+
public function webhook($headers, $body) : object;
134135

135136
/**
136137
* Verify that a given Pusher Signature is valid.

0 commit comments

Comments
 (0)