Moved the action type and paused or not from the signature to the separate class

This commit is contained in:
Vitaliy Dotsenko
2019-07-08 21:09:19 +03:00
parent 68d862f7da
commit 22a87e1b91
2 changed files with 55 additions and 14 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Cloudflare\API\Configurations;
class FirewallRuleOptions implements Configurations
{
protected $configs = [
'paused' => 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';
}
}

View File

@@ -3,6 +3,7 @@
namespace Cloudflare\API\Endpoints; namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\FirewallRuleOptions;
class Firewall implements API class Firewall implements API
{ {
@@ -32,19 +33,16 @@ class Firewall implements API
public function createFirewallRule( public function createFirewallRule(
string $zoneID, string $zoneID,
string $expression, string $expression,
string $action, FirewallRuleOptions $options,
string $description = null, string $description = null,
bool $paused = false,
int $priority = null int $priority = null
): bool { ): bool {
$rule = [ $rule = array_merge([
'filter' => [ 'filter' => [
'expression' => $expression, 'expression' => $expression,
'paused' => false 'paused' => false
], ]
'action' => $action, ], $options->getArray());
'paused' => $paused
];
if ($description !== null) { if ($description !== null) {
$rule['description'] = $description; $rule['description'] = $description;
@@ -93,21 +91,18 @@ class Firewall implements API
string $ruleID, string $ruleID,
string $filterID, string $filterID,
string $expression, string $expression,
string $action, FirewallRuleOptions $options,
string $description = null, string $description = null,
bool $paused = true,
int $priority = null int $priority = null
): \stdClass { ): \stdClass {
$rule = [ $rule = array_merge([
'id' => $ruleID, 'id' => $ruleID,
'filter' => [ 'filter' => [
'id' => $filterID, 'id' => $filterID,
'expression' => $expression, 'expression' => $expression,
'paused' => false 'paused' => false
], ]
'action' => $action, ], $options->getArray());
'paused' => $paused
];
if ($description !== null) { if ($description !== null) {
$rule['description'] = $description; $rule['description'] = $description;