Skip to content

Commit 678ef8f

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

File tree

7 files changed

+256
-59
lines changed

7 files changed

+256
-59
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/Servers/Server.php

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

0 commit comments

Comments
 (0)