|
| 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 | +} |
0 commit comments