Skip to content

Commit b17ae6e

Browse files
authored
Merge pull request #90 from squeezely/loadbalancers
LoadBalancers + LoadBalancers Pool endpoint integration
2 parents b558622 + 1724b66 commit b17ae6e

18 files changed

+1310
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
/**
3+
* @author Martijn Smidt <[email protected]>
4+
* User: HemeraOne
5+
* Date: 13/05/2019
6+
*/
7+
8+
namespace Cloudflare\API\Configurations;
9+
10+
class LoadBalancer implements Configurations
11+
{
12+
private $configs = [];
13+
14+
public function __construct(string $name, array $defaultPools, string $fallbackPool)
15+
{
16+
$this->setName($name);
17+
$this->setDefaultPools($defaultPools);
18+
$this->setFallbackPool($fallbackPool);
19+
}
20+
21+
public function setName(string $name)
22+
{
23+
$this->configs['name'] = $name;
24+
}
25+
26+
public function getName():string
27+
{
28+
return $this->configs['name'] ?? '';
29+
}
30+
31+
public function setDefaultPools(array $defaultPools)
32+
{
33+
$this->configs['default_pools'] = $defaultPools;
34+
}
35+
36+
public function getDefaultPools():array
37+
{
38+
return $this->configs['default_pools'] ?? [];
39+
}
40+
41+
public function setFallbackPool(string $fallbackPool)
42+
{
43+
$this->configs['fallback_pools'] = $fallbackPool;
44+
}
45+
46+
public function getFallbackPool():string
47+
{
48+
return $this->configs['fallback_pools'] ?? '';
49+
}
50+
51+
public function setSteeringPolicy(string $steeringPolicy = '')
52+
{
53+
$allowedOptions = ['off', 'geo', 'random', 'dynamic_latency', ''];
54+
if (!in_array($steeringPolicy, $allowedOptions)) {
55+
throw new ConfigurationsException('Given steering policy value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
56+
}
57+
58+
$this->configs['steering_policy'] = $steeringPolicy;
59+
}
60+
61+
public function getSteeringPolicy():string
62+
{
63+
return $this->configs['steering_policy'] ?? '';
64+
}
65+
66+
public function enable()
67+
{
68+
$this->configs['enabled'] = true;
69+
}
70+
71+
public function isEnabled():bool
72+
{
73+
return $this->configs['enabled'] ?? true;
74+
}
75+
76+
public function disable()
77+
{
78+
$this->configs['enabled'] = false;
79+
}
80+
81+
public function isDisabled():bool
82+
{
83+
return !$this->configs['enabled'] ?? false;
84+
}
85+
86+
public function getEnabled():bool
87+
{
88+
return $this->configs['enabled'] ?? true;
89+
}
90+
91+
public function setPopPools(array $popPools)
92+
{
93+
$this->configs['pop_pools'] = $popPools;
94+
}
95+
96+
public function getPopPools():array
97+
{
98+
return $this->configs['pop_pools'] ?? [];
99+
}
100+
101+
public function setTtl(int $ttl)
102+
{
103+
$this->configs['ttl'] = $ttl;
104+
}
105+
106+
public function getTtl():int
107+
{
108+
return $this->configs['ttl'] ?? 30;
109+
}
110+
111+
public function setRegionPools(array $regionPools)
112+
{
113+
$this->configs['region_pools'] = $regionPools;
114+
}
115+
116+
public function getRegionPools():array
117+
{
118+
return $this->configs['region_pools'] ?? [];
119+
}
120+
121+
public function setSessionAffinity(string $sessionAffinity = '')
122+
{
123+
$allowedOptions = ['none', 'cookie', 'ip_cookie', ''];
124+
if (!in_array($sessionAffinity, $allowedOptions)) {
125+
throw new ConfigurationsException('Given session affinity value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
126+
}
127+
$this->configs['session_affinity'] = $sessionAffinity;
128+
}
129+
130+
public function getSessionAffinity():string
131+
{
132+
return $this->configs['session_affinity'] ?? '';
133+
}
134+
135+
public function setDescription(string $description = '')
136+
{
137+
$this->configs['description'] = $description;
138+
}
139+
140+
public function getDescription():string
141+
{
142+
return $this->configs['description'] ?? '';
143+
}
144+
145+
public function enableProxied()
146+
{
147+
$this->configs['proxied'] = true;
148+
}
149+
150+
public function disableProxied()
151+
{
152+
$this->configs['proxied'] = false;
153+
}
154+
155+
public function isProxied():bool
156+
{
157+
return $this->configs['proxied'] ?? true;
158+
}
159+
160+
public function setSessionAffinityTtl(int $sessionAffinityTtl = 82800)
161+
{
162+
if ($sessionAffinityTtl > 604800 || $sessionAffinityTtl < 1800) {
163+
throw new ConfigurationsException('The value of session affinity ttl must be between 1800 and 604800');
164+
}
165+
166+
$this->configs['session_affinity_ttl'] = $sessionAffinityTtl;
167+
}
168+
169+
public function getSessionAffinityTtl():int
170+
{
171+
return $this->configs['session_affinity_ttl'] ?? 82800;
172+
}
173+
174+
public function getArray(): array
175+
{
176+
return $this->configs;
177+
}
178+
}

src/Configurations/Pool.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* @author Martijn Smidt <[email protected]>
4+
* User: HemeraOne
5+
* Date: 13/05/2019
6+
*/
7+
8+
namespace Cloudflare\API\Configurations;
9+
10+
class Pool implements Configurations
11+
{
12+
private $configs = [];
13+
14+
public function __construct(string $name, array $origins)
15+
{
16+
$this->setName($name);
17+
$this->setOrigins($origins);
18+
}
19+
20+
public function setName(string $name)
21+
{
22+
$this->configs['name'] = $name;
23+
}
24+
25+
public function getName():string
26+
{
27+
return $this->configs['name'] ?? '';
28+
}
29+
30+
public function setOrigins(array $origins)
31+
{
32+
foreach ($origins as $origin) {
33+
if (!isset($origin['name'])) {
34+
throw new ConfigurationsException('name is required for origin');
35+
}
36+
if (!isset($origin['address'])) {
37+
throw new ConfigurationsException('address is required for origin');
38+
}
39+
}
40+
$this->configs['origins'] = $origins;
41+
}
42+
43+
public function getOrigins():array
44+
{
45+
return $this->configs['origins'] ?? [];
46+
}
47+
48+
public function setDescription(string $description = '')
49+
{
50+
$this->configs['description'] = $description;
51+
}
52+
53+
public function getDescription():string
54+
{
55+
return $this->configs['description'] ?? '';
56+
}
57+
58+
public function enable()
59+
{
60+
$this->configs['enabled'] = true;
61+
}
62+
63+
public function isEnabled():bool
64+
{
65+
return $this->configs['enabled'] ?? true;
66+
}
67+
68+
public function disable()
69+
{
70+
$this->configs['enabled'] = false;
71+
}
72+
73+
public function isDisabled():bool
74+
{
75+
return !$this->configs['enabled'] ?? false;
76+
}
77+
78+
public function getEnabled():bool
79+
{
80+
return $this->configs['enabled'] ?? true;
81+
}
82+
83+
public function setMonitor(string $monitor)
84+
{
85+
$this->configs['monitor'] = $monitor;
86+
}
87+
88+
public function getMonitor():string
89+
{
90+
return $this->configs['monitor'] ?? '';
91+
}
92+
93+
public function setCheckRegions(array $checkRegions)
94+
{
95+
$this->configs['check_regions'] = $checkRegions;
96+
}
97+
98+
public function getCheckRegions():array
99+
{
100+
return $this->configs['check_regions'] ?? [];
101+
}
102+
103+
public function setNotificationEmail(string $email)
104+
{
105+
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
106+
throw new ConfigurationsException('Invalid notification email given');
107+
}
108+
109+
$this->configs['notification_email'] = $email;
110+
}
111+
112+
public function getNotificationEmail():string
113+
{
114+
return $this->configs['notification_email'] ?? '';
115+
}
116+
117+
public function getArray(): array
118+
{
119+
return $this->configs;
120+
}
121+
}

0 commit comments

Comments
 (0)