1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EdwinLuijten\Ekko\Broadcast\Broadcasters; |
4
|
|
|
|
5
|
|
|
use EdwinLuijten\Ekko\Broadcast\Identity; |
6
|
|
|
use EdwinLuijten\Ekko\Broadcast\StrUtil; |
7
|
|
|
use Pusher; |
8
|
|
|
|
9
|
|
|
class PusherBroadcaster extends AbstractBroadcaster implements BroadcasterInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Pusher |
13
|
|
|
*/ |
14
|
|
|
private $pusher; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* PusherBroadcaster constructor. |
18
|
9 |
|
* @param Pusher $pusher |
19
|
|
|
*/ |
20
|
9 |
|
public function __construct(Pusher $pusher) |
21
|
9 |
|
{ |
22
|
|
|
$this->pusher = $pusher; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Identity $identity |
27
|
|
|
* @return mixed |
28
|
|
|
* @throws \Exception |
29
|
|
|
*/ |
30
|
|
|
public function auth(Identity $identity) |
31
|
3 |
|
{ |
32
|
|
|
if (StrUtil::startsWith($identity->channel, ['private-', 'presence-']) && empty($identity->identifier)) { |
33
|
3 |
|
throw new \Exception('Unauthorized', 403); |
34
|
3 |
|
} |
35
|
|
|
|
36
|
|
|
return parent::verifyThatIdentityCanAccessChannel( |
|
|
|
|
37
|
|
|
$identity, |
38
|
|
|
str_replace(['private-', 'presence-'], '', $identity->channel) |
39
|
|
|
); |
40
|
|
|
} |
41
|
3 |
|
|
42
|
|
|
/** |
43
|
3 |
|
* @param Identity $identity |
44
|
|
|
* @param $response |
45
|
|
|
* @return string signature |
46
|
|
|
*/ |
47
|
|
|
public function validAuthenticationResponse(Identity $identity, $response) |
48
|
|
|
{ |
49
|
|
|
if (StrUtil::startsWith($identity->channel, 'private')) { |
50
|
|
|
return $this->pusher->socket_auth($identity->channel, $identity->socketId); |
51
|
|
|
} else { |
52
|
|
|
return $this->pusher->presence_auth( |
53
|
|
|
$identity->channel, |
54
|
|
|
$identity->socketId, |
55
|
|
|
$identity->identifier, |
56
|
|
|
$response |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Broadcast the given event. |
63
|
|
|
* |
64
|
|
|
* @param array $channels |
65
|
|
|
* @param string $event |
66
|
|
|
* @param array $payload |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
public function broadcast(array $channels, $event, array $payload = []) |
70
|
|
|
{ |
71
|
|
|
$socket = isset($payload['socket']) ? $payload['socket'] : null; |
72
|
|
|
|
73
|
|
|
$this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the Pusher instance. |
78
|
|
|
* |
79
|
|
|
* @return Pusher |
80
|
|
|
*/ |
81
|
|
|
public function getPusher() |
82
|
|
|
{ |
83
|
|
|
return $this->pusher; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.