1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Botonomous; |
4
|
|
|
|
5
|
|
|
use Botonomous\listener\AbstractBaseListener; |
6
|
|
|
use Botonomous\utility\FormattingUtility; |
7
|
|
|
use Botonomous\utility\LoggerUtility; |
8
|
|
|
use Botonomous\utility\MessageUtility; |
9
|
|
|
use Botonomous\utility\RequestUtility; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AbstractBot. |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractBot |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Dependencies. |
18
|
|
|
*/ |
19
|
|
|
protected $config; |
20
|
|
|
protected $listener; |
21
|
|
|
protected $messageUtility; |
22
|
|
|
protected $commandContainer; |
23
|
|
|
protected $formattingUtility; |
24
|
|
|
protected $loggerUtility; |
25
|
|
|
protected $oauth; |
26
|
|
|
protected $blackList; |
27
|
|
|
protected $whiteList; |
28
|
|
|
protected $sender; |
29
|
|
|
protected $dictionary; |
30
|
|
|
protected $commandExtractor; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return Config |
34
|
|
|
*/ |
35
|
41 |
|
public function getConfig() |
36
|
|
|
{ |
37
|
41 |
|
if ($this->config === null) { |
38
|
35 |
|
$this->config = (new Config()); |
39
|
|
|
} |
40
|
|
|
|
41
|
41 |
|
return $this->config; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Config $config |
46
|
|
|
*/ |
47
|
10 |
|
public function setConfig(Config $config) |
48
|
|
|
{ |
49
|
10 |
|
$this->config = $config; |
50
|
10 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return AbstractBaseListener |
54
|
|
|
*/ |
55
|
31 |
|
public function getListener() |
56
|
|
|
{ |
57
|
31 |
|
if (!isset($this->listener)) { |
58
|
29 |
|
$listenerClass = __NAMESPACE__.'\\listener\\'.ucwords($this->getConfig()->get('listener')).'Listener'; |
59
|
29 |
|
$this->setListener(new $listenerClass()); |
60
|
|
|
} |
61
|
|
|
|
62
|
31 |
|
return $this->listener; |
63
|
|
|
} |
64
|
|
|
|
65
|
31 |
|
public function setListener(AbstractBaseListener $listener) |
66
|
|
|
{ |
67
|
31 |
|
$this->listener = $listener; |
68
|
31 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return MessageUtility |
72
|
|
|
*/ |
73
|
3 |
|
public function getMessageUtility() |
74
|
|
|
{ |
75
|
3 |
|
if (!isset($this->messageUtility)) { |
76
|
3 |
|
$this->setMessageUtility(new MessageUtility()); |
77
|
|
|
} |
78
|
|
|
|
79
|
3 |
|
return $this->messageUtility; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param MessageUtility $messageUtility |
84
|
|
|
*/ |
85
|
3 |
|
public function setMessageUtility(MessageUtility $messageUtility) |
86
|
|
|
{ |
87
|
3 |
|
$this->messageUtility = $messageUtility; |
88
|
3 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return CommandContainer |
92
|
|
|
*/ |
93
|
1 |
|
public function getCommandContainer() |
94
|
|
|
{ |
95
|
1 |
|
if (!isset($this->commandContainer)) { |
96
|
1 |
|
$this->setCommandContainer(new CommandContainer()); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
return $this->commandContainer; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param CommandContainer $commandContainer |
104
|
|
|
*/ |
105
|
1 |
|
public function setCommandContainer(CommandContainer $commandContainer) |
106
|
|
|
{ |
107
|
1 |
|
$this->commandContainer = $commandContainer; |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return FormattingUtility |
112
|
|
|
*/ |
113
|
2 |
|
public function getFormattingUtility() |
114
|
|
|
{ |
115
|
2 |
|
if (!isset($this->formattingUtility)) { |
116
|
1 |
|
$this->setFormattingUtility(new FormattingUtility()); |
117
|
|
|
} |
118
|
|
|
|
119
|
2 |
|
return $this->formattingUtility; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param FormattingUtility $formattingUtility |
124
|
|
|
*/ |
125
|
2 |
|
public function setFormattingUtility(FormattingUtility $formattingUtility) |
126
|
|
|
{ |
127
|
2 |
|
$this->formattingUtility = $formattingUtility; |
128
|
2 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return LoggerUtility |
132
|
|
|
*/ |
133
|
1 |
|
public function getLoggerUtility() |
134
|
|
|
{ |
135
|
1 |
|
if (!isset($this->loggerUtility)) { |
136
|
1 |
|
$this->setLoggerUtility(new LoggerUtility()); |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
return $this->loggerUtility; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param LoggerUtility $loggerUtility |
144
|
|
|
*/ |
145
|
1 |
|
public function setLoggerUtility(LoggerUtility $loggerUtility) |
146
|
|
|
{ |
147
|
1 |
|
$this->loggerUtility = $loggerUtility; |
148
|
1 |
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return OAuth |
152
|
|
|
*/ |
153
|
2 |
|
public function getOauth() |
154
|
|
|
{ |
155
|
2 |
|
if (!isset($this->oauth)) { |
156
|
1 |
|
$this->setOauth(new OAuth()); |
157
|
|
|
} |
158
|
|
|
|
159
|
2 |
|
return $this->oauth; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param OAuth $oauth |
164
|
|
|
*/ |
165
|
2 |
|
public function setOauth(OAuth $oauth) |
166
|
|
|
{ |
167
|
2 |
|
$this->oauth = $oauth; |
168
|
2 |
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return RequestUtility |
172
|
|
|
*/ |
173
|
2 |
|
public function getRequestUtility() |
174
|
|
|
{ |
175
|
2 |
|
return $this->getListener()->getRequestUtility(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param RequestUtility $requestUtility |
180
|
|
|
*/ |
181
|
3 |
|
public function setRequestUtility(RequestUtility $requestUtility) |
182
|
|
|
{ |
183
|
3 |
|
$this->getListener()->setRequestUtility($requestUtility); |
184
|
3 |
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return BlackList |
188
|
|
|
*/ |
189
|
1 |
|
public function getBlackList() |
190
|
|
|
{ |
191
|
1 |
|
if (!isset($this->blackList)) { |
192
|
|
|
$this->setBlackList(new BlackList($this->getListener()->getRequest())); |
193
|
|
|
} |
194
|
|
|
|
195
|
1 |
|
return $this->blackList; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param BlackList $blackList |
200
|
|
|
*/ |
201
|
1 |
|
public function setBlackList(BlackList $blackList) |
202
|
|
|
{ |
203
|
1 |
|
$this->blackList = $blackList; |
204
|
1 |
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return WhiteList |
208
|
|
|
*/ |
209
|
|
|
public function getWhiteList() |
210
|
|
|
{ |
211
|
|
|
if (!isset($this->whiteList)) { |
212
|
|
|
$this->setWhiteList(new WhiteList($this->getListener()->getRequest())); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
return $this->whiteList; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param WhiteList $whiteList |
220
|
|
|
*/ |
221
|
|
|
public function setWhiteList(WhiteList $whiteList) |
222
|
|
|
{ |
223
|
|
|
$this->whiteList = $whiteList; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return Sender |
228
|
|
|
*/ |
229
|
3 |
|
public function getSender() |
230
|
|
|
{ |
231
|
3 |
|
if (!isset($this->sender)) { |
232
|
3 |
|
$this->setSender(new Sender($this)); |
233
|
|
|
} |
234
|
|
|
|
235
|
3 |
|
return $this->sender; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param Sender $sender |
240
|
|
|
*/ |
241
|
3 |
|
public function setSender(Sender $sender) |
242
|
|
|
{ |
243
|
3 |
|
$this->sender = $sender; |
244
|
3 |
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return Dictionary |
248
|
|
|
*/ |
249
|
2 |
|
public function getDictionary() |
250
|
|
|
{ |
251
|
2 |
|
if (!isset($this->dictionary)) { |
252
|
2 |
|
$this->setDictionary(new Dictionary()); |
253
|
|
|
} |
254
|
|
|
|
255
|
2 |
|
return $this->dictionary; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param Dictionary $dictionary |
260
|
|
|
*/ |
261
|
2 |
|
public function setDictionary(Dictionary $dictionary) |
262
|
|
|
{ |
263
|
2 |
|
$this->dictionary = $dictionary; |
264
|
2 |
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return CommandExtractor |
268
|
|
|
*/ |
269
|
4 |
|
public function getCommandExtractor() |
270
|
|
|
{ |
271
|
4 |
|
if (!isset($this->commandExtractor)) { |
272
|
4 |
|
$this->setCommandExtractor(new CommandExtractor()); |
273
|
|
|
} |
274
|
|
|
|
275
|
4 |
|
return $this->commandExtractor; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param CommandExtractor $commandExtractor |
280
|
|
|
*/ |
281
|
4 |
|
public function setCommandExtractor(CommandExtractor $commandExtractor) |
282
|
|
|
{ |
283
|
4 |
|
$this->commandExtractor = $commandExtractor; |
284
|
4 |
|
} |
285
|
|
|
} |
286
|
|
|
|