result = $callable(); } catch (GuzzleException $e) { // no response at all (connection refused, timeout) throw CollectionException::unreachable($e); } if (!$this->result->success()) { throw CollectionException::fromResult($this->result); } } /** * @throws CollectionException */ public static function builder(callable $callable): static { return new static($callable, false); } /** * Returns the collection of resources as an array. */ public function toArray(): array { return (array)$this->result->data; } /** * Returns the collection of resources as a JSON string. */ public function jsonSerialize(): array { return $this->toArray(); } /** * Returns the collection of resources. */ public function paginate(): Result { return $this->result; } /** * Returns the Resource based on the ID. */ abstract public function find(string $id): ?BaseResource; public function __get(string $name) { return $this->result->{$name} ?? null; } public function __isset(string $name): bool { return isset($this->result->{$name}); } }