Note: This library is under active development as I expand it to cover Cloudflare API. Consider the public API of this package a little unstable as I work towards a v1.0. See Coverage.

Rulesets

The Cloudflare Ruleset Engine allows you to create and deploy rules and rulesets in different Cloudflare products using the same basic syntax.

Cloudflare API docs

List

Fetches all rulesets at the zone level.

php
$response = $client->zones()->rulesets()->get('ZONE_ID');

Create

Creates a ruleset at the zone level.

php
use Cloudflare\Configurations\Rules\BlockRule;
use Cloudflare\Configurations\Ruleset;

$ruleset = (new Ruleset('The human-readable name of the ruleset.'))
    ->managed() //Set Ruleset kind to 'managed'
    ->configSettings() //Set Ruleset phase to 'http_config_settings'
    ->setDescription('An informative description of the ruleset.');

//Create a BlockRule
$blockRule = new BlockRule(['title' => 'My Response Title', 'text' => 'My response text'], 'application/json', 400);

$blockRule->setExpression(function(ExpressionBuilder $builder){
    return $builder->field('ip.src')->eq('192.168.1.2')->or()->group(function(ExpressionBuilder $bilder){
        $bilder->not()->field('ssl')->or()->field('udp')->contains(32);
    })->or()->addExpression('ip.src', 'eq', '127.0.01');
});

$ruleset->addRule($blockRule);

$response = $client->zones()->rulesets()->create('ZONE_ID', $ruleset);

Details

Fetches the latest version of a zone ruleset.

php
$response = $client->zones()->rulesets()->details('ZONE_ID', 'RULESET_ID');

Delete

Deletes all versions of an existing zone ruleset.

php
$response = $client->zones()->rulesets()->delete('ZONE_ID', 'RULESET_ID');
Table of Contents