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;
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;