|
| 1 | +# Upgrade Guide: v2.x to v3.0 |
| 2 | + |
| 3 | +This guide provides instructions for upgrading your application from `hetzner-cloud-php-sdk` version 2.x to 3.0. |
| 4 | + |
| 5 | +## Breaking Changes |
| 6 | + |
| 7 | +### PHP Version Requirement |
| 8 | +- **Requirement:** PHP 8.2 or higher is now required. |
| 9 | +- **Action:** Ensure your server or environment is running PHP 8.2+. |
| 10 | + |
| 11 | +### Removal of `illuminate/collections` |
| 12 | +The dependency on `illuminate/collections` has been removed to reduce the library's footprint and avoid dependency conflicts. All internal usages of `collect()` have been replaced with native PHP array functions. |
| 13 | + |
| 14 | +- **Impact:** If your application relied on the SDK returning Laravel Collections, this will no longer happen. |
| 15 | +- **Action:** Use native PHP array functions like `array_map()`, `array_filter()`, or wrap the returned arrays in a collection yourself if you still need them. |
| 16 | + |
| 17 | +**Before (v2.x):** |
| 18 | +```php |
| 19 | +// Some internal methods or if you were using collect() on SDK results |
| 20 | +$names = collect($hetznerClient->servers()->all())->map(fn($s) => $s->name); |
| 21 | +``` |
| 22 | + |
| 23 | +**After (v3.0):** |
| 24 | +```php |
| 25 | +// Results are now always native arrays |
| 26 | +$servers = $hetznerClient->servers()->all(); |
| 27 | +$names = array_map(fn($s) => $s->name, $servers); |
| 28 | + |
| 29 | +// If you want to keep using Collections in your project: |
| 30 | +// composer require illuminate/collections |
| 31 | +$names = collect($hetznerClient->servers()->all())->map(fn($s) => $s->name); |
| 32 | +``` |
| 33 | + |
| 34 | +### `delete()` Method Return Type Change |
| 35 | +The `delete()` method on all resource models now returns an `APIResponse` object (or `null`) instead of a `boolean`. This provides more information about the API response, such as the `Action` created by the deletion. |
| 36 | + |
| 37 | +- **Impact:** Any code checking for `if ($model->delete())` will still work as `APIResponse` is truthy, but it is better to update your logic if you were relying on the boolean result. |
| 38 | + |
| 39 | +**Before (v2.x):** |
| 40 | +```php |
| 41 | +$success = $server->delete(); // returned bool |
| 42 | +if ($success) { |
| 43 | + // ... |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +**After (v3.0):** |
| 48 | +```php |
| 49 | +$response = $server->delete(); // returns ?APIResponse |
| 50 | +if ($response !== null) { |
| 51 | + $action = $response->action; // You can now access the action |
| 52 | + // ... |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Native Type Hints |
| 57 | +Many method signatures have been updated to include native PHP 8.1 type hints. This improves IDE support and static analysis. |
| 58 | + |
| 59 | +- **Impact:** If you have extended SDK classes and overridden methods, you may need to update your method signatures to match the new type hints to avoid PHP fatal errors. |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## New Features |
| 64 | +Version 3.0 also introduces several new features and improvements: |
| 65 | +- Support for **Primary IPs**. |
| 66 | +- Support for **Placement Groups**. |
| 67 | +- Support for **Firewalls** (including label selectors). |
| 68 | +- Improved support for **Load Balancers**. |
| 69 | +- Improved support for **Managed Certificates**. |
| 70 | + |
| 71 | +## Summary for LLMs |
| 72 | +- Minimum PHP: `8.2` |
| 73 | +- Dependency removed: `illuminate/collections` |
| 74 | +- `delete()` returns: `?LKDev\HetznerCloud\APIResponse` (was `bool`) |
| 75 | +- All list methods return: `array` |
| 76 | +- Models use native type hints for parameters and return types. |
0 commit comments