From c9f6187c533d51cef842bc64f162b0ebb4062e32 Mon Sep 17 00:00:00 2001 From: Jens Prangenberg Date: Wed, 18 Mar 2026 21:42:54 +0100 Subject: [PATCH 1/5] Make `public_net` parameter optional in server management methods --- src/Models/Servers/Servers.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Models/Servers/Servers.php b/src/Models/Servers/Servers.php index 6334137..ce7c7f9 100644 --- a/src/Models/Servers/Servers.php +++ b/src/Models/Servers/Servers.php @@ -174,7 +174,7 @@ public function createInDatacenter( $networks = [], array $labels = [], array $firewalls = [], - array $public_net = [], + ?array $public_net = null, ?int $placement_group = null ): ?APIResponse { $parameters = [ @@ -188,7 +188,6 @@ public function createInDatacenter( 'volumes' => $volumes, 'automount' => $automount, 'networks' => $networks, - 'public_net' => $public_net, ]; if (! empty($labels)) { $parameters['labels'] = $labels; @@ -199,6 +198,9 @@ public function createInDatacenter( if ($placement_group != null) { $parameters['placement_group'] = $placement_group; } + if ($public_net != null) { + $parameters['public_net'] = $public_net; + } $response = $this->httpClient->post('servers', [ 'json' => $parameters, ]); @@ -252,7 +254,7 @@ public function createInLocation(string $name, array $networks = [], array $labels = [], array $firewalls = [], - array $public_net = [], + ?array $public_net = null, ?int $placement_group = null ): ?APIResponse { $parameters = [ @@ -266,7 +268,6 @@ public function createInLocation(string $name, 'volumes' => $volumes, 'automount' => $automount, 'networks' => $networks, - 'public_net' => $public_net, ]; if (! empty($labels)) { $parameters['labels'] = $labels; @@ -277,6 +278,9 @@ public function createInLocation(string $name, if ($placement_group != null) { $parameters['placement_group'] = $placement_group; } + if ($public_net != null) { + $parameters['public_net'] = $public_net; + } $response = $this->httpClient->post('servers', [ 'json' => $parameters, ]); From c61ddf74184152b36277436f127079947437f521 Mon Sep 17 00:00:00 2001 From: Jens Prangenberg Date: Fri, 20 Mar 2026 12:57:06 +0100 Subject: [PATCH 2/5] Add deprecation field to ServerType model The Hetzner API returns a `deprecation` object for server types that are no longer available for new bookings. Map this field so consumers can filter out deprecated types without making a separate API call. Co-Authored-By: Claude Sonnet 4.6 --- src/Models/Servers/Types/ServerType.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index 71851d6..e7dafdb 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -63,6 +63,13 @@ class ServerType extends Model */ public $architecture; + /** + * Deprecation info if the server type is deprecated, null otherwise. + * + * @var array{announced: string, unavailable_after: string}|null + */ + public $deprecation; + /** * ServerType constructor. * @@ -91,6 +98,7 @@ public function setAdditionalData($input) $this->storageType = $input->storage_type ?? null; $this->cpuType = $input->cpu_type ?? null; $this->architecture = property_exists($input, 'architecture') ? $input->architecture : null; + $this->deprecation = property_exists($input, 'deprecation') ? (array) $input->deprecation : null; return $this; } From 32530b153ef1384635eba3297299818baa6a9967 Mon Sep 17 00:00:00 2001 From: Jens Prangenberg Date: Fri, 20 Mar 2026 13:02:16 +0100 Subject: [PATCH 3/5] Fix deprecation field mapping: preserve null when API returns null (array) null evaluates to [] not null, so the null-check for filtering deprecated server types never matched. Explicitly guard against null before casting to array. Co-Authored-By: Claude Sonnet 4.6 --- src/Models/Servers/Types/ServerType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index e7dafdb..d6c3418 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -98,7 +98,7 @@ public function setAdditionalData($input) $this->storageType = $input->storage_type ?? null; $this->cpuType = $input->cpu_type ?? null; $this->architecture = property_exists($input, 'architecture') ? $input->architecture : null; - $this->deprecation = property_exists($input, 'deprecation') ? (array) $input->deprecation : null; + $this->deprecation = (property_exists($input, 'deprecation') && $input->deprecation !== null) ? (array) $input->deprecation : null; return $this; } From 29cbfaad16a54f77d1765df60cb2d0a241b2a22e Mon Sep 17 00:00:00 2001 From: Jens Prangenberg Date: Fri, 20 Mar 2026 13:05:46 +0100 Subject: [PATCH 4/5] Add locationAvailability field to ServerType model Hetzner deprecates server types per location via a nested locations array. This field maps location name to its deprecation info (null = still available), enabling per-location availability checks. Co-Authored-By: Claude Sonnet 4.6 --- src/Models/Servers/Types/ServerType.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index d6c3418..204bdf8 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -70,6 +70,14 @@ class ServerType extends Model */ public $deprecation; + /** + * Per-location availability info, keyed by location name. + * Each entry contains a deprecation object or null if still available. + * + * @var array + */ + public $locationAvailability = []; + /** * ServerType constructor. * @@ -99,6 +107,11 @@ public function setAdditionalData($input) $this->cpuType = $input->cpu_type ?? null; $this->architecture = property_exists($input, 'architecture') ? $input->architecture : null; $this->deprecation = (property_exists($input, 'deprecation') && $input->deprecation !== null) ? (array) $input->deprecation : null; + $this->locationAvailability = collect($input->locations ?? []) + ->mapWithKeys(fn ($loc): array => [ + $loc->name => ($loc->deprecation !== null) ? (array) $loc->deprecation : null, + ]) + ->all(); return $this; } From 0305f30a674961d9a9f11eec3652a914433f9af4 Mon Sep 17 00:00:00 2001 From: Jens Prangenberg Date: Fri, 20 Mar 2026 13:08:32 +0100 Subject: [PATCH 5/5] Fix collect() usage: replace with native PHP foreach collect() is a Laravel helper and not available in this standalone SDK. Co-Authored-By: Claude Sonnet 4.6 --- src/Models/Servers/Types/ServerType.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index 204bdf8..f760216 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -107,11 +107,11 @@ public function setAdditionalData($input) $this->cpuType = $input->cpu_type ?? null; $this->architecture = property_exists($input, 'architecture') ? $input->architecture : null; $this->deprecation = (property_exists($input, 'deprecation') && $input->deprecation !== null) ? (array) $input->deprecation : null; - $this->locationAvailability = collect($input->locations ?? []) - ->mapWithKeys(fn ($loc): array => [ - $loc->name => ($loc->deprecation !== null) ? (array) $loc->deprecation : null, - ]) - ->all(); + $locationAvailability = []; + foreach ($input->locations ?? [] as $loc) { + $locationAvailability[$loc->name] = ($loc->deprecation !== null) ? (array) $loc->deprecation : null; + } + $this->locationAvailability = $locationAvailability; return $this; }