Moved the action type and paused or not from the signature to the separate class
This commit is contained in:
46
src/Configurations/FirewallRuleOptions.php
Normal file
46
src/Configurations/FirewallRuleOptions.php
Normal 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';
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user