-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathFirewallResource.php
More file actions
58 lines (49 loc) · 1.21 KB
/
FirewallResource.php
File metadata and controls
58 lines (49 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace LKDev\HetznerCloud\Models\Firewalls;
use LKDev\HetznerCloud\Models\Servers\Server;
/**
* Class FirewallResource.
*/
class FirewallResource
{
const TYPE_SERVER = 'server';
const TYPE_LABEL_SELECTOR = 'label_selector';
/**
* @var string
*/
public $type;
/**
* @var ?Server
*/
public $server;
/**
* @var string|null
*/
public $selector;
/**
* FirewallResource constructor.
*
* @param string $type
* @param Server|null $server
* @param string|null $selector
*/
public function __construct(string $type, ?Server $server = null, ?string $selector = null)
{
$this->type = $type;
$this->server = $server;
$this->selector = $selector;
}
/**
* @return array
*/
public function toRequestSchema(): array
{
$s = ['type' => $this->type];
if ($this->type == self::TYPE_SERVER && $this->server !== null) {
$s['server'] = ['id' => $this->server->id];
} elseif ($this->type == self::TYPE_LABEL_SELECTOR && $this->selector !== null) {
$s['label_selector'] = ['selector' => $this->selector];
}
return $s;
}
}