1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DigitalOceanV2 library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DigitalOceanV2\Entity; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Jacob Holmes <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class LoadBalancer extends AbstractEntity |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
public $name; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $ip; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $algorithm; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $status; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
public $createdAt; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var ForwardingRule[] |
51
|
|
|
*/ |
52
|
|
|
public $forwardingRules; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var HealthCheck |
56
|
|
|
*/ |
57
|
|
|
public $healthCheck; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var StickySession |
61
|
|
|
*/ |
62
|
|
|
public $stickySessions; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var Region |
66
|
|
|
*/ |
67
|
|
|
public $region; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
public $tag; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var array |
76
|
|
|
*/ |
77
|
|
|
public $dropletIds; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var bool |
81
|
|
|
*/ |
82
|
|
|
public $redirectHttpToHttps; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $parameters |
86
|
|
|
*/ |
87
|
|
|
public function build(array $parameters) |
88
|
|
|
{ |
89
|
|
|
foreach ($parameters as $property => $value) { |
90
|
|
|
switch ($property) { |
91
|
|
|
case 'forwarding_rules': |
92
|
|
|
|
93
|
|
|
foreach ($value as $forwardingRule) { |
94
|
|
|
$this->forwardingRules[] = new ForwardingRule($forwardingRule); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
unset($parameters[$property]); |
98
|
|
|
break; |
99
|
|
|
|
100
|
|
|
case 'health_check': |
101
|
|
|
if (is_object($value)) { |
102
|
|
|
$this->healthCheck = new HealthCheck($value); |
103
|
|
|
} |
104
|
|
|
unset($parameters[$property]); |
105
|
|
|
break; |
106
|
|
|
|
107
|
|
|
case 'sticky_sessions': |
108
|
|
|
if (is_object($value)) { |
109
|
|
|
$this->stickySessions = new StickySession($value); |
110
|
|
|
} |
111
|
|
|
unset($parameters[$property]); |
112
|
|
|
break; |
113
|
|
|
|
114
|
|
|
case 'region': |
115
|
|
|
if (is_object($value)) { |
116
|
|
|
$this->region = new Region($value); |
117
|
|
|
} |
118
|
|
|
unset($parameters[$property]); |
119
|
|
|
break; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
parent::build($parameters); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
|
|
public function toArray() |
130
|
|
|
{ |
131
|
|
|
return [ |
132
|
|
|
'name' => $this->name, |
133
|
|
|
'region' => $this->region->slug, |
134
|
|
|
'algorithm' => $this->algorithm, |
135
|
|
|
'forwarding_rules' => array_map(function ($rule) { |
136
|
|
|
return $rule->toArray(); |
137
|
|
|
}, $this->forwardingRules), |
138
|
|
|
'health_check' => $this->healthCheck->toArray(), |
139
|
|
|
'sticky_sessions' => $this->stickySessions->toArray(), |
140
|
|
|
'droplet_ids' => $this->dropletIds, |
141
|
|
|
'redirect_http_to_https' => $this->redirectHttpToHttps, |
142
|
|
|
]; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|