1 | <?php |
||
17 | class ConversationManager implements Manager |
||
18 | { |
||
19 | private $intents = []; |
||
20 | private $fallbackIntent; |
||
21 | |||
22 | private $application; |
||
23 | private $cache; |
||
24 | |||
25 | private $transitioned = false; |
||
26 | |||
27 | private $messageReceived; |
||
28 | |||
29 | 71 | public function __construct(Application $application, Repository $cache) |
|
34 | |||
35 | /** |
||
36 | * Register intent. |
||
37 | * |
||
38 | * @param string $class |
||
39 | */ |
||
40 | public function registerIntent(string $class): void |
||
44 | |||
45 | /** |
||
46 | * Register fallback intent. |
||
47 | * |
||
48 | * @param string $class |
||
49 | */ |
||
50 | 71 | public function registerFallbackIntent(string $class): void |
|
54 | |||
55 | /** |
||
56 | * Get all registered intents. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getIntents(): array |
||
64 | |||
65 | /** |
||
66 | * Match intent by received message. |
||
67 | * |
||
68 | * @param MessageReceived $messageReceived |
||
69 | * |
||
70 | * @return Intent|null |
||
71 | */ |
||
72 | public function matchIntent(MessageReceived $messageReceived): ?Intent |
||
88 | |||
89 | /** |
||
90 | * Resolve conversation context. |
||
91 | * |
||
92 | * @param Channel $channel |
||
93 | * @param Chat $chat |
||
94 | * @param User $user |
||
95 | * |
||
96 | * @return Context|null |
||
97 | */ |
||
98 | public function resolveContext(Channel $channel, Chat $chat, User $user): Context |
||
122 | |||
123 | /** |
||
124 | * Save context. |
||
125 | * |
||
126 | * @param Context $context |
||
127 | */ |
||
128 | public function saveContext(Context $context): void |
||
135 | |||
136 | /** |
||
137 | * Flush context. |
||
138 | * |
||
139 | * @param Context $context |
||
140 | */ |
||
141 | public function flushContext(Context $context): void |
||
147 | |||
148 | /** |
||
149 | * Get current context. |
||
150 | * |
||
151 | * @return Context|null |
||
152 | */ |
||
153 | 71 | public function getContext(): ?Context |
|
161 | |||
162 | /** |
||
163 | * Define received message. |
||
164 | * |
||
165 | * @param MessageReceived $messageReceived |
||
166 | */ |
||
167 | public function setReceivedMessage(MessageReceived $messageReceived): void |
||
171 | |||
172 | /** |
||
173 | * Mark conversation as transitioned. |
||
174 | */ |
||
175 | public function markAsTransitioned(): void |
||
179 | |||
180 | /** |
||
181 | * Determine if conversation has been transitioned. |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function transitioned(): bool |
||
189 | |||
190 | /** |
||
191 | * Start conversation. |
||
192 | * |
||
193 | * @param Conversable $conversable |
||
194 | */ |
||
195 | public function converse(Conversable $conversable): void |
||
203 | |||
204 | /** |
||
205 | * Jump to interaction. |
||
206 | * |
||
207 | * @param string $conversable |
||
208 | */ |
||
209 | public function transition(string $conversable): void |
||
221 | |||
222 | /** |
||
223 | * Restart current dialog. |
||
224 | * |
||
225 | * @param Conversable $conversable |
||
226 | */ |
||
227 | public function restart(Conversable $conversable): void |
||
239 | |||
240 | 71 | public function __destruct() |
|
241 | { |
||
242 | 71 | $context = $this->getContext(); |
|
243 | |||
244 | 71 | if ($context === null) { |
|
245 | 71 | return; |
|
246 | } |
||
247 | |||
248 | // Close session if conversation has not been transitioned |
||
249 | if (!$this->transitioned()) { |
||
250 | $this->flushContext($context); |
||
251 | } |
||
252 | |||
253 | // Save context if exists |
||
254 | if ($this->transitioned() && $context = context()) { |
||
255 | $this->saveContext($context); |
||
256 | } |
||
257 | } |
||
258 | |||
259 | private function getCacheKeyForContext(Channel $channel, Chat $chat, User $user): string |
||
263 | } |
||
264 |
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: