1 | <?php |
||
20 | abstract class AbstractDriver implements Driver, SerializableForQueue |
||
21 | { |
||
22 | /** @var Collection */ |
||
23 | protected $parameters; |
||
24 | |||
25 | /** @var HttpRequest */ |
||
26 | protected $request; |
||
27 | |||
28 | /** @var HttpClient */ |
||
29 | private $httpClient; |
||
30 | |||
31 | /** @var RequestFactory */ |
||
32 | private $requestFactory; |
||
33 | |||
34 | public function __construct(HttpClient $httpClient, RequestFactory $requestFactory) |
||
39 | |||
40 | /** |
||
41 | * Get driver short name. |
||
42 | * |
||
43 | * This name is used as an alias for configuration. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getShortName(): string |
||
53 | |||
54 | /** |
||
55 | * Initialize gateway with parameters. |
||
56 | * |
||
57 | * @param array $parameters |
||
58 | * |
||
59 | * @param Request $request |
||
60 | * |
||
61 | * @return Driver|AbstractDriver|static |
||
62 | */ |
||
63 | 1 | public function initialize(array $parameters, Request $request): Driver |
|
79 | |||
80 | /** |
||
81 | * Get parameters. |
||
82 | * |
||
83 | * @return Collection |
||
84 | */ |
||
85 | 1 | public function getParameters(): Collection |
|
89 | |||
90 | /** |
||
91 | * Send HTTP request. |
||
92 | * |
||
93 | * @param string $method |
||
94 | * @param string $uri |
||
95 | * @param array $headers |
||
96 | * @param string|array|resource|StreamInterface|null $body |
||
97 | * @param string $protocolVersion |
||
98 | * |
||
99 | * @return ResponseInterface |
||
100 | */ |
||
101 | public function send( |
||
112 | |||
113 | /** |
||
114 | * Send a GET request. |
||
115 | * |
||
116 | * @param string $uri |
||
117 | * @param array $headers |
||
118 | * |
||
119 | * @return ResponseInterface |
||
120 | */ |
||
121 | public function get(string $uri, array $headers = []): ResponseInterface |
||
125 | |||
126 | /** |
||
127 | * Send a POST request. |
||
128 | * |
||
129 | * @param string $uri |
||
130 | * @param array $headers |
||
131 | * @param string|array|resource|StreamInterface|null $body |
||
132 | * |
||
133 | * @return ResponseInterface |
||
134 | */ |
||
135 | public function post(string $uri, array $headers = [], $body = null): ResponseInterface |
||
139 | |||
140 | /** |
||
141 | * Get template compiler instance. |
||
142 | * |
||
143 | * @return TemplateCompiler|null |
||
144 | */ |
||
145 | abstract public function getTemplateCompiler(): ?TemplateCompiler; |
||
146 | |||
147 | /** |
||
148 | * Get command handler instance. |
||
149 | * |
||
150 | * @return CommandHandler |
||
151 | */ |
||
152 | abstract public function getCommandHandler(): CommandHandler; |
||
153 | |||
154 | /** |
||
155 | * Verify incoming request data. |
||
156 | * |
||
157 | * @throws InvalidRequest |
||
158 | */ |
||
159 | abstract public function verifyRequest(): void; |
||
160 | |||
161 | /** |
||
162 | * Get current chat. |
||
163 | * |
||
164 | * @return Chat |
||
165 | */ |
||
166 | abstract public function getChat(): Chat; |
||
167 | |||
168 | /** |
||
169 | * Get current user. |
||
170 | * |
||
171 | * @return User |
||
172 | */ |
||
173 | abstract public function getUser(): User; |
||
174 | |||
175 | /** |
||
176 | * Get message received from sender. |
||
177 | * |
||
178 | * @return ReceivedMessage |
||
179 | */ |
||
180 | abstract public function getMessage(): ReceivedMessage; |
||
181 | |||
182 | /** |
||
183 | * Handle command. |
||
184 | * |
||
185 | * @param Command $command |
||
186 | * |
||
187 | * @throws RuntimeException |
||
188 | */ |
||
189 | 1 | public function handle(Command $command): void |
|
193 | } |
||
194 |