Consolidated some of the config/option creation

I've just added some internal methods to handle the casting and formatting of the
configuration/option creation.
This commit is contained in:
Anthony Sterling
2017-09-28 21:16:27 +01:00
parent 49ed1c9e8f
commit b7e70655ce

View File

@@ -14,38 +14,30 @@ class PageRulesActions implements Configurations
public function setAlwaysOnline(bool $active) public function setAlwaysOnline(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("always_online", [
$object->id = "always_online"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setAlwaysUseHTTPS(bool $active) public function setAlwaysUseHTTPS(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("always_use_https", [
$object->id = "always_use_https"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setBrowserCacheTTL(int $ttl) public function setBrowserCacheTTL(int $ttl)
{ {
$object = new \stdClass(); $this->addConfigurationOption("browser_cache_ttl", [
$object->id = "browser_cache_ttl"; 'value' => $ttl
$object->value = $ttl; ]);
array_push($this->configs, $object);
} }
public function setBrowserIntegrityCheck(bool $active) public function setBrowserIntegrityCheck(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("browser_check", [
$object->id = "browser_check"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setBypassCacheOnCookie(bool $value) public function setBypassCacheOnCookie(bool $value)
@@ -54,29 +46,23 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException("Invalid cookie string."); throw new ConfigurationsException("Invalid cookie string.");
} }
$object = new \stdClass(); $this->addConfigurationOption("bypass_cache_on_cookie", [
$object->id = "bypass_cache_on_cookie"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setCacheByDeviceType(bool $active) public function setCacheByDeviceType(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("cache_by_device_type", [
$object->id = "cache_by_device_type"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setCacheKey(string $value) public function setCacheKey(string $value)
{ {
$object = new \stdClass(); $this->addConfigurationOption("cache_key", [
$object->id = "cache_key"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setCacheLevel(string $value) public function setCacheLevel(string $value)
@@ -85,11 +71,9 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException("Invalid cache level"); throw new ConfigurationsException("Invalid cache level");
} }
$object = new \stdClass(); $this->addConfigurationOption("cache_level", [
$object->id = "cache_level"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setCacheOnCookie(bool $value) public function setCacheOnCookie(bool $value)
@@ -98,38 +82,30 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException("Invalid cookie string."); throw new ConfigurationsException("Invalid cookie string.");
} }
$object = new \stdClass(); $this->addConfigurationOption("cache_on_cookie", [
$object->id = "cache_on_cookie"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setDisableApps(bool $active) public function setDisableApps(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("disable_apps", [
$object->id = "disable_apps"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setDisablePerformance(bool $active) public function setDisablePerformance(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("disable_performance", [
$object->id = "disable_performance"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setDisableSecurity(bool $active) public function setDisableSecurity(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("disable_security", [
$object->id = "disable_security"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setEdgeCacheTTL(int $value) public function setEdgeCacheTTL(int $value)
@@ -138,135 +114,107 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException("Edge Cache TTL too high."); throw new ConfigurationsException("Edge Cache TTL too high.");
} }
$object = new \stdClass(); $this->addConfigurationOption("edge_cache_ttl", [
$object->id = "edge_cache_ttl"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setEmailObfuscation(bool $active) public function setEmailObfuscation(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("disable_security", [
$object->id = "disable_security"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setForwardingURL(int $statusCode, string $forwardingUrl) public function setForwardingURL(int $statusCode, string $forwardingUrl)
{ {
if (in_array($statusCode, ['301', '302'])) { if (!in_array($statusCode, ['301', '302'])) {
throw new ConfigurationsException('Status Codes can only be 301 or 302.'); throw new ConfigurationsException('Status Codes can only be 301 or 302.');
} }
$object = new \stdClass(); $this->addConfigurationOption("forwarding_url", [
$object->id = "forwarding_url"; 'status_code' => $statusCode,
$object->status_code = $statusCode; 'url' => $forwardingUrl,
$object->url = $forwardingUrl; ]);
array_push($this->configs, $object);
} }
public function setHostHeaderOverride(bool $active) public function setHostHeaderOverride(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("host_header_override", [
$object->id = "host_header_override"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setHotlinkProtection(bool $active) public function setHotlinkProtection(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("hotlink_protection", [
$object->id = "hotlink_protection"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setIPGeoLocationHeader(bool $active) public function setIPGeoLocationHeader(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("ip_geolocation", [
$object->id = "ip_geolocation"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setMinification(bool $html, bool $css, bool $js) public function setMinification(bool $html, bool $css, bool $js)
{ {
$object = new \stdClass(); $this->addConfigurationOption("minification", [
$object->id = "minification"; 'html' => $this->getBoolAsOnOrOff($html),
$object->html = $html === true ? "on" : "off"; 'css' => $this->getBoolAsOnOrOff($css),
$object->css = $css === true ? "on" : "off"; 'js' => $this->getBoolAsOnOrOff($js),
$object->js = $js === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setMirage(bool $active) public function setMirage(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("mirage", [
$object->id = "mirage"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setOriginErrorPagePassthru(bool $active) public function setOriginErrorPagePassthru(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("origin_error_page_pass_thru", [
$object->id = "origin_error_page_pass_thru"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setQueryStringSort(bool $active) public function setQueryStringSort(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("sort_query_string_for_cache", [
$object->id = "sort_query_string_for_cache"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setDisableRailgun(bool $active) public function setDisableRailgun(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("disable_railgun", [
$object->id = "disable_railgun"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setResolveOverride(bool $value) public function setResolveOverride(bool $value)
{ {
$object = new \stdClass(); $this->addConfigurationOption("resolve_override", [
$object->id = "resolve_override"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setRespectStrongEtag(bool $active) public function setRespectStrongEtag(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("respect_strong_etag", [
$object->id = "respect_strong_etag"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setResponseBuffering(bool $active) public function setResponseBuffering(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("response_buffering", [
$object->id = "response_buffering"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setRocketLoader(string $value) public function setRocketLoader(string $value)
@@ -275,11 +223,9 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.'); throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
} }
$object = new \stdClass(); $this->addConfigurationOption("rocket_loader", [
$object->id = "rocket_loader"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setSecurityLevel(string $value) public function setSecurityLevel(string $value)
@@ -288,29 +234,23 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.'); throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
} }
$object = new \stdClass(); $this->addConfigurationOption("security_level", [
$object->id = "security_level"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setServerSideExcludes(bool $active) public function setServerSideExcludes(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("server_side_exclude", [
$object->id = "server_side_exclude"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setSmartErrors(bool $active) public function setSmartErrors(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("smart_errors", [
$object->id = "smart_errors"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setSSL(string $value) public function setSSL(string $value)
@@ -319,51 +259,53 @@ class PageRulesActions implements Configurations
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.'); throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
} }
$object = new \stdClass(); $this->addConfigurationOption("smart_errors", [
$object->id = "smart_errors"; 'value' => $value
$object->value = $value; ]);
array_push($this->configs, $object);
} }
public function setTrueClientIpHeader(bool $active) public function setTrueClientIpHeader(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("true_client_ip_header", [
$object->id = "true_client_ip_header"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setWAF(bool $active) public function setWAF(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("waf", [
$object->id = "waf"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setAutomatedHTTPSRewrites(bool $active) public function setAutomatedHTTPSRewrites(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("automatic_https_rewrites", [
$object->id = "automatic_https_rewrites"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function setOpportunisticEncryption(bool $active) public function setOpportunisticEncryption(bool $active)
{ {
$object = new \stdClass(); $this->addConfigurationOption("opportunistic_encryption", [
$object->id = "opportunistic_encryption"; 'value' => $this->getBoolAsOnOrOff($active)
$object->value = $active === true ? "on" : "off"; ]);
array_push($this->configs, $object);
} }
public function getArray(): array public function getArray(): array
{ {
return $this->configs; return $this->configs;
} }
private function addConfigurationOption($id, array $configuration)
{
$configuration['id'] = $id;
array_push($this->configs, (object) $configuration);
}
private function getBoolAsOnOrOff(bool $value): string
{
return true === $value ? 'on' : 'off';
}
} }