diff --git a/src/Configurations/FirewallRuleOptions.php b/src/Configurations/FirewallRuleOptions.php new file mode 100644 index 0000000..93f0531 --- /dev/null +++ b/src/Configurations/FirewallRuleOptions.php @@ -0,0 +1,46 @@ + false, + 'action' => 'block' + ]; + + public function getArray(): array + { + return $this->configs; + } + + public function setPaused(bool $paused) + { + $this->configs['paused'] = $paused; + } + + public function setActionBlock() + { + $this->configs['action'] = 'block'; + } + + public function setActionAllow() + { + $this->configs['action'] = 'allow'; + } + + public function setActionChallenge() + { + $this->configs['action'] = 'challenge'; + } + + public function setActionJsChallenge() + { + $this->configs['action'] = 'js_challenge'; + } + + public function setActionLog() + { + $this->configs['action'] = 'log'; + } +} diff --git a/src/Endpoints/Firewall.php b/src/Endpoints/Firewall.php index 9772951..14ebb76 100644 --- a/src/Endpoints/Firewall.php +++ b/src/Endpoints/Firewall.php @@ -3,6 +3,7 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Configurations\FirewallRuleOptions; class Firewall implements API { @@ -32,19 +33,16 @@ class Firewall implements API public function createFirewallRule( string $zoneID, string $expression, - string $action, + FirewallRuleOptions $options, string $description = null, - bool $paused = false, int $priority = null ): bool { - $rule = [ + $rule = array_merge([ 'filter' => [ 'expression' => $expression, 'paused' => false - ], - 'action' => $action, - 'paused' => $paused - ]; + ] + ], $options->getArray()); if ($description !== null) { $rule['description'] = $description; @@ -93,21 +91,18 @@ class Firewall implements API string $ruleID, string $filterID, string $expression, - string $action, + FirewallRuleOptions $options, string $description = null, - bool $paused = true, int $priority = null ): \stdClass { - $rule = [ + $rule = array_merge([ 'id' => $ruleID, 'filter' => [ 'id' => $filterID, 'expression' => $expression, 'paused' => false - ], - 'action' => $action, - 'paused' => $paused - ]; + ] + ], $options->getArray()); if ($description !== null) { $rule['description'] = $description;