id = $id; $this->api = new Api(); $this->endpoint = $endpoint; $this->resolve_entity_by_id(); } private function resolve_entity_by_id() { // Bail out wit a dummy Response if no id was provided if (!$this->id) { $this->response = new Response("", 404); return; } $this->response = $this->api ->call($this->endpoint->value) ->params([self::ENTITY_ID => $this->id]) ->get(); // Load response into entity object if successful if ($this->response->ok) { $this->entity = (object) $this->response->json()[0]; } } public function resolve(Endpoints $endpoint, array $params): array { $response = $this->api->call($endpoint->value)->params($params)->get(); return $response->ok ? $response->json() : []; } }