1 | <?php |
||
14 | class HttpClient |
||
15 | { |
||
16 | /** @var Worker */ |
||
17 | private $worker; |
||
18 | |||
19 | /** @var []callable Array of termination event listeners */ |
||
20 | private $terminationListeners = []; |
||
21 | |||
22 | /** |
||
23 | * @param Worker $worker |
||
24 | */ |
||
25 | public function __construct(Worker $worker) |
||
29 | |||
30 | /** |
||
31 | * @return Worker |
||
32 | */ |
||
33 | public function getWorker(): Worker |
||
37 | |||
38 | /** |
||
39 | * @return array|null Request information as ['ctx'=>[], 'body'=>string] or null if termination request or invalid context. |
||
40 | */ |
||
41 | public function acceptRequest() |
||
62 | |||
63 | /** |
||
64 | * Send response to the application server. |
||
65 | * |
||
66 | * @param int $status Http status code |
||
67 | * @param string $body Body of response |
||
68 | * @param string[][] $headers An associative array of the message's headers. Each |
||
69 | * key MUST be a header name, and each value MUST be an array of strings |
||
70 | * for that header. |
||
71 | */ |
||
72 | public function respond(int $status, string $body, array $headers = []) |
||
84 | |||
85 | /** |
||
86 | * Adds function to termination event listeners |
||
87 | * |
||
88 | * @param callable $func Function to call on termination request |
||
89 | * @throws \ReflectionException |
||
90 | */ |
||
91 | public function addTerminationListener(callable $func) |
||
99 | |||
100 | /** |
||
101 | * Clears all termination event listeners |
||
102 | */ |
||
103 | public function clearTerminationListeners() |
||
107 | } |
||
108 |