|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Crummy\Phlack\Common; |
|
4
|
|
|
|
|
5
|
|
|
use Crummy\Phlack\Bridge\Guzzle\PhlackClient; |
|
6
|
|
|
use Crummy\Phlack\Common\Formatter\Sequencer; |
|
7
|
|
|
use Crummy\Phlack\Common\Responder\ResponderInterface; |
|
8
|
|
|
use Crummy\Phlack\Message\MessageInterface; |
|
9
|
|
|
use Crummy\Phlack\WebHook\CommandInterface; |
|
10
|
|
|
use Crummy\Phlack\WebHook\Reply\EmptyReply; |
|
11
|
|
|
use Crummy\Phlack\WebHook\Reply\Reply; |
|
12
|
|
|
|
|
13
|
|
|
class Iterocitor implements ResponderInterface |
|
14
|
|
|
{ |
|
15
|
|
|
private $client; |
|
16
|
|
|
private $sequencer; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param array $options |
|
20
|
|
|
*/ |
|
21
|
8 |
|
public function __construct($options = []) |
|
22
|
|
|
{ |
|
23
|
8 |
|
$this->sequencer = new Sequencer(); |
|
24
|
|
|
|
|
25
|
8 |
|
if ($options instanceof PhlackClient) { |
|
26
|
8 |
|
$this->client = $options; |
|
27
|
8 |
|
} else { |
|
28
|
|
|
$this->client = new PhlackClient($options); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
8 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
6 |
|
public function say($text) |
|
36
|
|
|
{ |
|
37
|
6 |
|
return new Reply(['text' => $text]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* "Emotes" a message into the channel. |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function emote($text) |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->important('channel', $text); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Send a message to a user. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $user user_id |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function tell($user, $text) |
|
56
|
|
|
{ |
|
57
|
2 |
|
return $this->say($this->sequencer->format('@'.$user).' '.$text); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Respond with a reply to a user. |
|
62
|
|
|
* |
|
63
|
|
|
* @param CommandInterface|string user_id, or a CommandInterface containing user_id and user_name. |
|
64
|
|
|
* @param $text |
|
65
|
|
|
* |
|
66
|
|
|
* @return Reply |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public function reply($user, $text) |
|
69
|
|
|
{ |
|
70
|
2 |
|
if ($user instanceof CommandInterface) { |
|
71
|
1 |
|
$sequence = $this->sequencer->command($user); |
|
72
|
|
|
|
|
73
|
1 |
|
return $this->say($sequence['user'].' '.$text); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
return $this->tell($user, $text); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function send(MessageInterface $message) |
|
83
|
|
|
{ |
|
84
|
1 |
|
$command = $this->client->getCommand('Send', $message->jsonSerialize()); |
|
85
|
|
|
|
|
86
|
1 |
|
$this->client->execute($command); |
|
87
|
|
|
|
|
88
|
1 |
|
return new EmptyReply(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param string $text |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Crummy\Phlack\WebHook\Reply\Reply |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function shout($text) |
|
97
|
|
|
{ |
|
98
|
1 |
|
return $this->important('everyone', $text); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param string $where |
|
103
|
|
|
* @param string $text |
|
104
|
|
|
* |
|
105
|
|
|
* @return Reply |
|
106
|
|
|
*/ |
|
107
|
2 |
|
protected function important($where, $text) |
|
108
|
|
|
{ |
|
109
|
2 |
|
return $this->say($this->sequencer->alert($where).' '.$text); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: