Skip to content

Commit 279c266

Browse files
authored
Allow overriding of client configuration on custom GuzzleClient. (#40)
1 parent 610b48f commit 279c266

File tree

10 files changed

+28
-22
lines changed

10 files changed

+28
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## master
4+
* Bugfix: Fix wrong Guzzle Client Type on Server, Volume and FloatingIp Model.
5+
* Feature: Allow overriding of Guzzle Client configuration on `LKDev\HetznerCloud\Clients\GuzzleClient`
6+
37
## 2.0.1 (29.01.2020)
48
* Bugfix: Floating IP description which can be null [#36](https://github.com/LKDevelopment/hetzner-cloud-php-sdk/pull/36)
59

src/APIException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace LKDev\HetznerCloud;
44

5-
use GuzzleHttp\Psr7\Response;
6-
75
class APIException extends \Exception
86
{
97
/**

src/Clients/GuzzleClient.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ class GuzzleClient extends Client
99
{
1010
/**
1111
* @param HetznerAPIClient $client
12+
* @param array $additionalGuzzleConfig
1213
*/
13-
public function __construct(HetznerAPIClient $client)
14+
public function __construct(HetznerAPIClient $client, $additionalGuzzleConfig = [])
1415
{
15-
parent::__construct([
16+
$guzzleConfig = array_merge([
1617
'base_uri' => $client->getBaseUrl(),
1718
'headers' => [
1819
'Authorization' => 'Bearer '.$client->getApiToken(),
1920
'Content-Type' => 'application/json',
2021
'User-Agent' => ((strlen($client->getUserAgent()) > 0) ? $client->getUserAgent().' ' : '').'hcloud-php/'.HetznerAPIClient::VERSION,
2122
],
22-
]);
23+
], $additionalGuzzleConfig);
24+
parent::__construct($guzzleConfig);
2325
}
2426
}

src/Models/FloatingIps/FloatingIp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function changeReverseDNS(string $ip, string $dnsPtr): APIResponse
256256

257257
/**
258258
* @param $input
259-
* @return \LKDev\HetznerCloud\Models\FloatingIps\FloatingIp|static
259+
* @return \LKDev\HetznerCloud\Models\FloatingIps\FloatingIp|static|null
260260
*/
261261
public static function parse($input): self
262262
{

src/Models/Model.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
namespace LKDev\HetznerCloud\Models;
44

55
use GuzzleHttp\Client;
6-
use LKDev\HetznerCloud\Clients\GuzzleClient;
76
use LKDev\HetznerCloud\HetznerAPIClient;
87

98
abstract class Model
109
{
1110
/**
12-
* @var \LKDev\HetznerCloud\Clients\GuzzleClient
11+
* @var \GuzzleHttp\Client
1312
*/
1413
protected $httpClient;
1514

1615
/**
1716
* Model constructor.
18-
* @param GuzzleClient $httpClient
17+
* @param Client $httpClient
1918
*/
2019
public function __construct(Client $httpClient = null)
2120
{

src/Models/Networks/Network.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace LKDev\HetznerCloud\Models\Networks;
44

5+
use GuzzleHttp\Client;
56
use LKDev\HetznerCloud\APIResponse;
6-
use LKDev\HetznerCloud\Clients\GuzzleClient;
77
use LKDev\HetznerCloud\HetznerAPIClient;
88
use LKDev\HetznerCloud\Models\Actions\Action;
99
use LKDev\HetznerCloud\Models\Contracts\Resource;
@@ -56,9 +56,9 @@ class Network extends Model implements Resource
5656
/**
5757
* Network constructor.
5858
* @param int $id
59-
* @param GuzzleClient|null $httpClient
59+
* @param Client|null $httpClient
6060
*/
61-
public function __construct(int $id, GuzzleClient $httpClient = null)
61+
public function __construct(int $id, Client $httpClient = null)
6262
{
6363
$this->id = $id;
6464
parent::__construct($httpClient);

src/Models/Networks/Route.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LKDev\HetznerCloud\Models\Networks;
44

5+
use GuzzleHttp\Client;
56
use LKDev\HetznerCloud\Clients\GuzzleClient;
67
use LKDev\HetznerCloud\Models\Model;
78

@@ -23,9 +24,9 @@ class Route extends Model
2324
* Subnet constructor.
2425
* @param string $destination
2526
* @param string $gateway
26-
* @param GuzzleClient|null $client
27+
* @param Client|null $client
2728
*/
28-
public function __construct(string $destination, string $gateway, GuzzleClient $client = null)
29+
public function __construct(string $destination, string $gateway, Client $client = null)
2930
{
3031
$this->destination = $destination;
3132
$this->gateway = $gateway;

src/Models/Networks/Subnet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LKDev\HetznerCloud\Models\Networks;
44

5+
use GuzzleHttp\Client;
56
use LKDev\HetznerCloud\Clients\GuzzleClient;
67
use LKDev\HetznerCloud\Models\Model;
78

@@ -11,6 +12,7 @@
1112
class Subnet extends Model
1213
{
1314
const TYPE_SERVER = 'server';
15+
const TYPE_CLOUD = 'cloud';
1416
/**
1517
* @var string
1618
*/
@@ -34,9 +36,9 @@ class Subnet extends Model
3436
* @param string $ipRange
3537
* @param string $networkZone
3638
* @param string $gateway
37-
* @param GuzzleClient|null $client
39+
* @param Client|null $client
3840
*/
39-
public function __construct(string $type, string $ipRange, string $networkZone, string $gateway = null, GuzzleClient $client = null)
41+
public function __construct(string $type, string $ipRange, string $networkZone, string $gateway = null, Client $client = null)
4042
{
4143
$this->type = $type;
4244
$this->ipRange = $ipRange;

src/Models/Servers/Server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
namespace LKDev\HetznerCloud\Models\Servers;
1010

11+
use GuzzleHttp\Client;
1112
use LKDev\HetznerCloud\APIResponse;
12-
use LKDev\HetznerCloud\Clients\GuzzleClient;
1313
use LKDev\HetznerCloud\HetznerAPIClient;
1414
use LKDev\HetznerCloud\Models\Actions\Action;
1515
use LKDev\HetznerCloud\Models\Contracts\Resource;
@@ -119,9 +119,9 @@ class Server extends Model implements Resource
119119

120120
/**
121121
* @param int $serverId
122-
* @param GuzzleClient|null $httpClient
122+
* @param Client|null $httpClient
123123
*/
124-
public function __construct(int $serverId, GuzzleClient $httpClient = null)
124+
public function __construct(int $serverId, Client $httpClient = null)
125125
{
126126
$this->id = $serverId;
127127
parent::__construct($httpClient);

src/Models/Volumes/Volume.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
namespace LKDev\HetznerCloud\Models\Volumes;
1010

11+
use GuzzleHttp\Client;
1112
use LKDev\HetznerCloud\APIResponse;
12-
use LKDev\HetznerCloud\Clients\GuzzleClient;
1313
use LKDev\HetznerCloud\HetznerAPIClient;
1414
use LKDev\HetznerCloud\Models\Actions\Action;
1515
use LKDev\HetznerCloud\Models\Contracts\Resource;
@@ -64,9 +64,9 @@ class Volume extends Model implements Resource
6464

6565
/**
6666
* @param int $volumeId
67-
* @param GuzzleClient|null $httpClient
67+
* @param Client|null $httpClient
6868
*/
69-
public function __construct(int $volumeId = null, GuzzleClient $httpClient = null)
69+
public function __construct(int $volumeId = null, Client $httpClient = null)
7070
{
7171
$this->id = $volumeId;
7272
parent::__construct($httpClient);

0 commit comments

Comments
 (0)