|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace FondBot\Conversation\Traits; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Collection; |
|
8
|
|
|
use FondBot\Conversation\Activators\Exact; |
|
9
|
|
|
use FondBot\Conversation\Activators\InArray; |
|
10
|
|
|
use FondBot\Conversation\Activators\Pattern; |
|
11
|
|
|
use FondBot\Conversation\Activators\Contains; |
|
12
|
|
|
use FondBot\Conversation\Activators\Activator; |
|
13
|
|
|
use FondBot\Conversation\Activators\WithPayload; |
|
14
|
|
|
use FondBot\Conversation\Activators\WithAttachment; |
|
15
|
|
|
|
|
16
|
|
|
trait HasActivators |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Intent activators. |
|
20
|
|
|
* |
|
21
|
|
|
* @return Activator[] |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract public function activators(): array; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Create "Exact" activator. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $value |
|
29
|
|
|
* |
|
30
|
|
|
* @param bool $caseSensitive |
|
31
|
|
|
* |
|
32
|
|
|
* @return Exact |
|
33
|
|
|
*/ |
|
34
|
1 |
|
protected function exact(string $value, bool $caseSensitive = false): Exact |
|
35
|
|
|
{ |
|
36
|
1 |
|
return new Exact($value, $caseSensitive); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string|array $needles |
|
41
|
|
|
* |
|
42
|
|
|
* @return Contains |
|
43
|
|
|
*/ |
|
44
|
1 |
|
protected function contains($needles): Contains |
|
45
|
|
|
{ |
|
46
|
1 |
|
return new Contains($needles); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create "Pattern" activator. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $value |
|
53
|
|
|
* |
|
54
|
|
|
* @return Pattern |
|
55
|
|
|
*/ |
|
56
|
1 |
|
protected function pattern(string $value): Pattern |
|
57
|
|
|
{ |
|
58
|
1 |
|
return new Pattern($value); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Create "InArray" activator. |
|
63
|
|
|
* |
|
64
|
|
|
* @param array|Collection $values |
|
65
|
|
|
* @param bool $strict |
|
66
|
|
|
* |
|
67
|
|
|
* @return InArray |
|
68
|
|
|
*/ |
|
69
|
1 |
|
protected function inArray($values, bool $strict = true): InArray |
|
70
|
|
|
{ |
|
71
|
1 |
|
return new InArray($values, $strict); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Create "WithAttachment" activator. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string|null $type |
|
78
|
|
|
* |
|
79
|
|
|
* @return WithAttachment |
|
80
|
|
|
*/ |
|
81
|
1 |
|
protected function withAttachment(string $type = null): WithAttachment |
|
82
|
|
|
{ |
|
83
|
1 |
|
return new WithAttachment($type); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Create "WithPayload" activator. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $value |
|
90
|
|
|
* |
|
91
|
|
|
* @return WithPayload |
|
92
|
|
|
*/ |
|
93
|
1 |
|
protected function withPayload(string $value): WithPayload |
|
94
|
|
|
{ |
|
95
|
1 |
|
return new WithPayload($value); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|