Skip to content

Commit 9e2686f

Browse files
committed
Improve Server Object Typing
Signed-off-by: Lukas Kämmerling <[email protected]>
1 parent d59ddd0 commit 9e2686f

File tree

8 files changed

+303
-62
lines changed

8 files changed

+303
-62
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+
## unreleased
4+
* Feature: Add Certificate Support
5+
* Improvements: Improve typing and structure of Server response
6+
37
## 2.2.1 (22.07.2020)
48
* Make package requirements less strict
59
* Bugfix: getByName functions had a wrong return type and failed when a resource was not found by name [#50](https://github.com/LKDevelopment/hetzner-cloud-php-sdk/issues/50)

src/Models/Certificates/Certificate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function delete(): bool
130130
*/
131131
public static function parse($input)
132132
{
133-
return new self($input->id, $input->name, $input->certificate, $input->created, $input->not_valid_before, $input->not_valid_after, $input->domain_names, $input->fingerprint, $input->used_by, $input->labels);
133+
return new self($input->id, $input->name, $input->certificate, $input->created, $input->not_valid_before, $input->not_valid_after, $input->domain_names, $input->fingerprint, $input->used_by, get_object_vars($input->labels));
134134
}
135135

136136
/**

src/Models/Servers/Server.php

Lines changed: 74 additions & 61 deletions
Large diffs are not rendered by default.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
4+
namespace LKDev\HetznerCloud\Models\Servers;
5+
6+
7+
8+
class ServerPrivateNet
9+
{
10+
/**
11+
* @var int
12+
*/
13+
public $network;
14+
/**
15+
* @var string
16+
*/
17+
public $ip;
18+
/**
19+
* @var string[]
20+
*/
21+
public $aliasIps;
22+
/**
23+
* @var string
24+
*/
25+
public $macAddress;
26+
27+
/**
28+
* ServerPrivateNet constructor.
29+
* @param int $network
30+
* @param string $ip
31+
* @param string[] $aliasIps
32+
* @param string $macAddress
33+
*/
34+
public function __construct(int $network, string $ip, array $aliasIps, string $macAddress)
35+
{
36+
$this->network = $network;
37+
$this->ip = $ip;
38+
$this->aliasIps = $aliasIps;
39+
$this->macAddress = $macAddress;
40+
}
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
4+
namespace LKDev\HetznerCloud\Models\Servers;
5+
6+
7+
/**
8+
* Class ServerPublicNet
9+
* @package LKDev\HetznerCloud\Models\Servers
10+
*/
11+
class ServerPublicNet
12+
{
13+
/**
14+
* @var ServerPublicNetIPv4
15+
*/
16+
public $ipv4;
17+
/**
18+
* @var ServerPublicNetIPv6
19+
*/
20+
public $ipv6;
21+
/**
22+
* @var int[]
23+
*/
24+
public $floatingIps;
25+
26+
/**
27+
* ServerPublicNet constructor.
28+
* @param ServerPublicNetIPv4 $ipv4
29+
* @param ServerPublicNetIPv6 $ipv6
30+
* @param array $floatingIps
31+
*/
32+
public function __construct(ServerPublicNetIPv4 $ipv4, ServerPublicNetIPv6 $ipv6, array $floatingIps)
33+
{
34+
$this->ipv4 = $ipv4;
35+
$this->ipv6 = $ipv6;
36+
$this->floatingIps = $floatingIps;
37+
}
38+
39+
/**
40+
* @param \stdClass $data
41+
* @return ServerPublicNet
42+
*/
43+
public static function parse(\stdClass $data)
44+
{
45+
return new ServerPublicNet(ServerPublicNetIPv4::parse($data->ipv4), ServerPublicNetIPv6::parse($data->ipv6), $data->floating_ips);
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
4+
namespace LKDev\HetznerCloud\Models\Servers;
5+
6+
7+
/**
8+
* Class ServerPublicNetIPv4
9+
* @package LKDev\HetznerCloud\Models\Servers
10+
*/
11+
class ServerPublicNetIPv4
12+
{
13+
/**
14+
* @var string
15+
*/
16+
public $ip;
17+
/**
18+
* @var bool
19+
*/
20+
public $blocked;
21+
/**
22+
* @var string
23+
*/
24+
public $dnsPtr;
25+
26+
/**
27+
* ServerPublicNetIPv4 constructor.
28+
* @param string $ip
29+
* @param bool $blocked
30+
* @param string $dnsPtr
31+
*/
32+
public function __construct(string $ip, bool $blocked, string $dnsPtr)
33+
{
34+
$this->ip = $ip;
35+
$this->blocked = $blocked;
36+
$this->dnsPtr = $dnsPtr;
37+
}
38+
39+
/**
40+
* @param \stdClass $data
41+
* @return ServerPublicNetIPv4
42+
*/
43+
public static function parse(\stdClass $data)
44+
{
45+
return new self($data->ip, $data->blocked, $data->dns_ptr);
46+
}
47+
48+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
4+
namespace LKDev\HetznerCloud\Models\Servers;
5+
6+
7+
/**
8+
* Class ServerPublicNetIPv6
9+
* @package LKDev\HetznerCloud\Models\Servers
10+
*/
11+
class ServerPublicNetIPv6
12+
{
13+
/**
14+
* @var string
15+
*/
16+
public $ip;
17+
/**
18+
* @var bool
19+
*/
20+
public $blocked;
21+
/**
22+
* @var array
23+
*/
24+
public $dnsPtr;
25+
26+
/**
27+
* ServerPublicNetIPv6 constructor.
28+
* @param string $ip
29+
* @param bool $blocked
30+
* @param array $dnsPtr
31+
*/
32+
public function __construct(string $ip, bool $blocked, array $dnsPtr)
33+
{
34+
$this->ip = $ip;
35+
$this->blocked = $blocked;
36+
$this->dnsPtr = $dnsPtr;
37+
}
38+
39+
/**
40+
* @param \stdClass $data
41+
* @return ServerPublicNetIPv6
42+
*/
43+
public static function parse(\stdClass $data)
44+
{
45+
$dnsPtrs = [];
46+
foreach ($data->dns_ptr as $dnsPtr) {
47+
$dnsPtrs[] = new ServerPublicNetIPv6DnsPtr($dnsPtr->ip, $dnsPtr->dns_ptr);
48+
}
49+
return new self($data->ip, $data->blocked, $dnsPtrs);
50+
}
51+
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
4+
namespace LKDev\HetznerCloud\Models\Servers;
5+
6+
7+
/**
8+
* Class ServerPublicNetIPv6DnsPtr
9+
* @package LKDev\HetznerCloud\Models\Servers
10+
*/
11+
class ServerPublicNetIPv6DnsPtr
12+
{
13+
/**
14+
* @var string
15+
*/
16+
public $ip;
17+
18+
/**
19+
* @var string
20+
*/
21+
public $dnsPtr;
22+
23+
/**
24+
* ServerPublicNetIPv6DnsPtr constructor.
25+
* @param string $ip
26+
* @param string $dnsPtr
27+
*/
28+
public function __construct(string $ip, string $dnsPtr)
29+
{
30+
$this->ip = $ip;
31+
$this->dnsPtr = $dnsPtr;
32+
}
33+
34+
35+
36+
}

0 commit comments

Comments
 (0)