url = new Uri($url); }elseif($url instanceof Uri){ $this->url = $url; }else{ throw new \Exception("Invalid url {$url}"); } if(is_array($headers)){ $this->headers = $headers; }else{ $this->headers = []; } $this->body = $body; } public function __get($name){ switch($name){ case 'headers': return $this->headers; break; case 'url': return $this->url; break; case 'body': return $this->body; break; } } public function header($name){ return $this->headers[$name] ?? null; } public function json(){ return json_decode($this->body, true); } public function text(){ return $this->body; } } ?>