From 9c7c882b04440905d174ef42e7ffc347f4e49c0b Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Wed, 18 Jan 2023 12:35:34 +0000 Subject: [PATCH] Further testing and fixing --- src/Concerns/ApiAccess.php | 4 ++-- src/Models/BaseModel.php | 8 +++++--- src/Models/Host.php | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Concerns/ApiAccess.php b/src/Concerns/ApiAccess.php index 30dc0c5..f09aec3 100644 --- a/src/Concerns/ApiAccess.php +++ b/src/Concerns/ApiAccess.php @@ -30,7 +30,7 @@ public static function createAccessToken(string $baseUrl, string $email, string ] ]); - $token = json_decode($response->getBody()->getContents()); + $token = json_decode($response->getBody()->getContents(), true); } catch (\Exception $e) { throw new \Exception('Unable to get access token: ' . $e->getMessage()); } @@ -74,6 +74,6 @@ protected function request(string $type, string $endpoint, ?array $query = null, 'json' => $data, ]); - return json_decode($response->getBody()->getContents()); + return json_decode($response->getBody()->getContents(), true); } } \ No newline at end of file diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php index 4e74541..8674b4b 100644 --- a/src/Models/BaseModel.php +++ b/src/Models/BaseModel.php @@ -8,12 +8,14 @@ abstract class BaseModel { public static function fromArray(array $data): static { - $host = new static; + $model = new static; foreach ($data as $k => $v) { - if (property_exists($host, $k)) { - $host->{$k} = $v; + if (property_exists($model, $k)) { + $model->{$k} = $v; } } + + return $model; } } \ No newline at end of file diff --git a/src/Models/Host.php b/src/Models/Host.php index 3f3c1bd..6397dcd 100644 --- a/src/Models/Host.php +++ b/src/Models/Host.php @@ -32,7 +32,7 @@ class Host extends BaseModel implements Model public bool $http2_support = true; - public array $locations = []; + public ?array $locations = []; public array $meta = [ 'dns_challenge' => true,