*/ private array $queue = []; /** @var list */ public array $requests = []; public function queue(int $status, array|string $body): self { $this->queue[] = new HttpResponse($status, is_string($body) ? $body : json_encode($body, JSON_THROW_ON_ERROR)); return $this; } public function get(string $url, array $query = [], array $headers = []): HttpResponse { return $this->take('GET', $url, $query, $headers); } public function postForm(string $url, array $fields): HttpResponse { return $this->take('POST', $url, $fields, []); } /** @return list */ public function requestsOf(string $method): array { return array_values(array_filter($this->requests, fn(array $r) => $r['method'] === $method)); } private function take(string $method, string $url, array $params, array $headers): HttpResponse { $this->requests[] = ['method' => $method, 'url' => $url, 'params' => $params, 'headers' => $headers]; if ($this->queue === []) { throw new \LogicException("Geen response gepland voor $method $url"); } return array_shift($this->queue); } }