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;
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user