Added pools class and tests

Small changes in loadbalancer configuration
This commit is contained in:
Martijn Smidt
2019-05-13 16:49:32 +02:00
parent 3cfeedbe4d
commit 99c174bcb3
14 changed files with 622 additions and 38 deletions

View File

@@ -28,9 +28,9 @@ class LoadBalancer implements Configurations
return $this->configs['name'] ?? '';
}
public function setDefaultPools(array $default_pools)
public function setDefaultPools(array $defaultPools)
{
$this->configs['default_pools'] = $default_pools;
$this->configs['default_pools'] = $defaultPools;
}
public function getDefaultPools():array
@@ -83,12 +83,7 @@ class LoadBalancer implements Configurations
return !$this->configs['enabled'] ?? false;
}
public function setEnabled(bool $enabled = true)
{
$this->configs['enabled'] = $enabled;
}
public function getEnabled(bool $enabled = true):bool
public function getEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
@@ -147,9 +142,14 @@ class LoadBalancer implements Configurations
return $this->configs['description'] ?? '';
}
public function setProxied(bool $proxied = true)
public function enableProxied()
{
$this->configs['proxied'] = $proxied;
$this->configs['proxied'] = true;
}
public function disableProxied()
{
$this->configs['proxied'] = false;
}
public function isProxied():bool

111
src/Configurations/Pool.php Normal file
View File

@@ -0,0 +1,111 @@
<?php
/**
* @author Martijn Smidt <martijn@squeezely.tech>
* User: HemeraOne
* Date: 13/05/2019
*/
namespace Cloudflare\API\Configurations;
class Pool implements Configurations
{
private $configs = [];
public function __construct(string $name, array $origins)
{
$this->setName($name);
$this->setOrigins($origins);
}
public function setName(string $name)
{
$this->configs['name'] = $name;
}
public function getName():string
{
return $this->configs['name'] ?? '';
}
public function setOrigins(array $origins)
{
foreach ($origins as $origin) {
if (!isset($origin['name'])) {
throw new ConfigurationsException('name is required for origin');
}
if (!isset($origin['address'])) {
throw new ConfigurationsException('address is required for origin');
}
}
$this->configs['origins'] = $origins;
}
public function getOrigins():array
{
return $this->configs['origins'] ?? [];
}
public function setDescription(string $description = '')
{
$this->configs['description'] = $description;
}
public function getDescription():string
{
return $this->configs['description'] ?? '';
}
public function enable()
{
$this->configs['enabled'] = true;
}
public function isEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function disable()
{
$this->configs['enabled'] = false;
}
public function isDisabled():bool
{
return !$this->configs['enabled'] ?? false;
}
public function getEnabled():bool
{
return $this->configs['enabled'] ?? true;
}
public function setMonitor(string $monitor)
{
$this->configs['monitor'] = $monitor;
}
public function getMonitor():string
{
return $this->configs['monitor'] ?? '';
}
public function setNotificationEmail(string $email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
throw new ConfigurationsException('Invalid notification email given');
}
$this->configs['notification_email'] = $email;
}
public function getNotificationEmail():string
{
return $this->configs['notification_email'] ?? '';
}
public function getArray(): array
{
return $this->configs;
}
}