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.

Page Rules

Cloudflare Page Rules allow you to make adjustments to requests, configure Cloudflare settings, and trigger specific actions for matching requests.

Cloudflare API docs

Settings

Returns a list of settings (and their details) that Page Rules can apply to matching requests.

php
$response = $client->zones()->pageRules()->settings('zone_id');

List

List, search, sort, and filter a zones Page Rules.

php
$response = $client->zones()->pageRules()->list('zone_id');

Create

Creates a new Page Rule for a zone.

php
$response = $client->zones()->pageRules()->create('zone_id', [
    'actions' => [],
    'targets' => [],
    'status' => 'active'
]);

Using PageRule Configuration helper.

php
use Cloudflare\Configurations\PageRule;

$target = "example.com/*";

$config = (new PageRule($target))
    ->setStatus(true)
    ->setPriority(100)
    ->cacheLevel('simplified')
    ->disableZaraz(true)
    ->edgeCacheTTL(600);

$response = $client->zones()->pageRules()->create('zone_id', $config);

Details

Fetches the details of a Page Rule.

php
$response = $client->zones()->pageRules()->details('zone_id', 'pageRuleId');

Update

Updates one or more fields of an existing Page Rule.

php
$response = $client->zones()->pageRules()->update('zone_id', 'pageRuleId', [
    'actions' => [],
    'targets' => [],
    'status' => 'active'
]);

Overwrite

Replaces the configuration of an existing Page Rule. The configuration of the updated Page Rule will exactly match the data passed in the API request.

php
$response = $client->zones()->pageRules()->overwrite('zone_id', 'pageRuleId', [
    'actions' => [],
    'targets' => [],
    'status' => 'active'
]);

Delete

Delete a Page Rule.

php
$response = $client->zones()->pageRules()->delete('zone_id', 'pageRuleId');