1 | <?php |
||
21 | class Kernel |
||
22 | { |
||
23 | public const VERSION = '1.0.0'; |
||
24 | |||
25 | /** @var Kernel */ |
||
26 | protected static $instance; |
||
27 | |||
28 | private $container; |
||
29 | |||
30 | /** @var Session|null */ |
||
31 | private $session; |
||
32 | |||
33 | 127 | private function __construct(Container $container) |
|
37 | |||
38 | 4 | public static function getInstance(): Kernel |
|
39 | { |
||
40 | 4 | return static::$instance; |
|
41 | } |
||
42 | |||
43 | 127 | public static function createInstance(Container $container): Kernel |
|
47 | |||
48 | /** |
||
49 | * Get current channel. |
||
50 | * |
||
51 | * @return Channel |
||
52 | * |
||
53 | * @throws \Psr\Container\ContainerExceptionInterface |
||
54 | */ |
||
55 | 5 | public function getChannel(): Channel |
|
56 | { |
||
57 | 5 | return $this->container->get('channel'); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get current driver instance. |
||
62 | * |
||
63 | * @return Driver |
||
64 | * |
||
65 | * @throws \Psr\Container\ContainerExceptionInterface |
||
66 | */ |
||
67 | 6 | public function getDriver(): Driver |
|
71 | |||
72 | /** |
||
73 | * Get session. |
||
74 | * |
||
75 | * @return Session|null |
||
76 | */ |
||
77 | 2 | public function getSession(): ?Session |
|
81 | |||
82 | /** |
||
83 | * Set session. |
||
84 | * |
||
85 | * @param Session $session |
||
86 | */ |
||
87 | 2 | public function setSession(Session $session): void |
|
91 | |||
92 | /** |
||
93 | * Clear session. |
||
94 | * |
||
95 | * @throws \Psr\Container\ContainerExceptionInterface |
||
96 | */ |
||
97 | 1 | public function clearSession(): void |
|
104 | |||
105 | /** |
||
106 | * Resolve an alias from container. |
||
107 | * |
||
108 | * @param string $alias |
||
109 | * @param array $args |
||
110 | * |
||
111 | * @return mixed |
||
112 | * |
||
113 | * @throws \Psr\Container\ContainerExceptionInterface |
||
114 | */ |
||
115 | 15 | public function resolve(string $alias, array $args = []) |
|
119 | |||
120 | /** |
||
121 | * Process webhook request. |
||
122 | * |
||
123 | * @param Channel $channel |
||
124 | * @param Request $request |
||
125 | * |
||
126 | * @return mixed |
||
127 | * |
||
128 | * @throws \Psr\Container\ContainerExceptionInterface |
||
129 | * @throws \FondBot\Drivers\Exceptions\DriverNotFound |
||
130 | * @throws \FondBot\Drivers\Exceptions\InvalidConfiguration |
||
131 | */ |
||
132 | 4 | public function process(Channel $channel, Request $request) |
|
170 | |||
171 | /** |
||
172 | * Start conversation. |
||
173 | * |
||
174 | * @param Conversable $conversable |
||
175 | */ |
||
176 | 2 | public function converse(Conversable $conversable): void |
|
188 | |||
189 | /** |
||
190 | * Get driver manager. |
||
191 | * |
||
192 | * @return DriverManager |
||
193 | * |
||
194 | * @throws \Psr\Container\ContainerExceptionInterface |
||
195 | */ |
||
196 | 4 | private function driverManager(): DriverManager |
|
200 | |||
201 | /** |
||
202 | * Get session manager. |
||
203 | * |
||
204 | * @return SessionManager |
||
205 | * |
||
206 | * @throws \Psr\Container\ContainerExceptionInterface |
||
207 | */ |
||
208 | 3 | private function sessionManager(): SessionManager |
|
212 | |||
213 | /** |
||
214 | * Get intent manager. |
||
215 | * |
||
216 | * @return IntentManager |
||
217 | * |
||
218 | * @throws \Psr\Container\ContainerExceptionInterface |
||
219 | */ |
||
220 | 1 | private function intentManager(): IntentManager |
|
224 | } |
||
225 |