Overview

Namespaces

  • Cloudflare
    • Organizations
      • Firewall
        • AccessRules
    • User
      • Billing
        • Subscriptions
      • Firewall
    • Zone
      • Firewall
      • SSL
      • WAF
        • Packages

Classes

  • Cloudflare\Api
  • Cloudflare\Certificates
  • Cloudflare\IPs
  • Cloudflare\Organizations\Firewall\AccessRules\Rules
  • Cloudflare\Organizations\Invites
  • Cloudflare\Organizations\Members
  • Cloudflare\Organizations\Organizations
  • Cloudflare\Organizations\Railguns
  • Cloudflare\Organizations\Roles
  • Cloudflare\Organizations\Virtual_Dns
  • Cloudflare\Railguns
  • Cloudflare\User
  • Cloudflare\User\Billing
  • Cloudflare\User\Billing\Subscriptions\Apps
  • Cloudflare\User\Billing\Subscriptions\Zones
  • Cloudflare\User\Firewall\AccessRules
  • Cloudflare\User\Invites
  • Cloudflare\User\Organizations
  • Cloudflare\User\Virtual_Dns
  • Cloudflare\Zone
  • Cloudflare\Zone\Analytics
  • Cloudflare\Zone\Cache
  • Cloudflare\Zone\CustomPages
  • Cloudflare\Zone\CustomSSL
  • Cloudflare\Zone\Dns
  • Cloudflare\Zone\Firewall\AccessRules
  • Cloudflare\Zone\KeylessSSL
  • Cloudflare\Zone\Pagerules
  • Cloudflare\Zone\Plan
  • Cloudflare\Zone\Railgun
  • Cloudflare\Zone\Settings
  • Cloudflare\Zone\SSL
  • Cloudflare\Zone\SSL\Analyze
  • Cloudflare\Zone\SSL\CertificatePacks
  • Cloudflare\Zone\WAF\Packages
  • Cloudflare\Zone\WAF\Packages\Groups
  • Cloudflare\Zone\WAF\Packages\Rules
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Cloudflare\Zone;
  4: 
  5: use Cloudflare\Api;
  6: use Cloudflare\Zone;
  7: 
  8: /**
  9:  * CloudFlare API wrapper
 10:  *
 11:  * Page rules for a Zone
 12:  * A rule describing target patterns for requests and actions to perform on matching requests
 13:  *
 14:  * @author James Bell <[email protected]>
 15:  *
 16:  * @version 1
 17:  */
 18: class Pagerules extends Api
 19: {
 20:     /**
 21:      * Default permissions level
 22:      *
 23:      * @var array
 24:      */
 25:     protected $permission_level = ['read' => '#zone:read', 'edit' => '#zone:edit'];
 26: 
 27:     /**
 28:      * Create a page rule [BETA] (permission needed: #zone:edit)
 29:      *
 30:      * @param string      $zone_identifier API item identifier tag
 31:      * @param array       $targets         Targets to evaluate on a request
 32:      * @param array       $actions         The set of actions to perform if the targets of this rule match the request.
 33:      *                                     Actions can redirect the url to another url or override settings (but not both)
 34:      * @param int|null    $priority        A number that indicates the preference for a page rule over another. In the case where
 35:      *                                     you may have a catch-all page rule (e.g., #1: '/images/') but want a rule that is more
 36:      *                                     specific to take precedence (e.g., #2: '/images/special/'), you'll want to specify a
 37:      *                                     higher priority on the latter (#2) so it will override the first.
 38:      * @param string|null $status          Status of the page rule
 39:      */
 40:     public function create($zone_identifier, $targets, $actions, $priority = null, $status = 'active')
 41:     {
 42:         $data = [
 43:             'targets'  => $targets,
 44:             'actions'  => $actions,
 45:             'priority' => $priority,
 46:             'status'   => $status,
 47:         ];
 48: 
 49:         return $this->post('zones/'.$zone_identifier.'/pagerules', $data);
 50:     }
 51: 
 52:     /**
 53:      * List page rules [BETA] (permission needed: #zone:read)
 54:      *
 55:      * @param string      $zone_identifier API item identifier tag
 56:      * @param string|null $status          Status of the page rule
 57:      * @param string|null $order           Field to order page rules by (status, priority)
 58:      * @param string|null $direction       Direction to order page rules (asc, desc)
 59:      * @param string|null $match           Whether to match all search requirements or at least one (any) (any, all)
 60:      */
 61:     public function list_pagerules($zone_identifier, $status = null, $order = null, $direction = null, $match = null)
 62:     {
 63:         $data = [
 64:             'status'    => $status,
 65:             'order'     => $order,
 66:             'direction' => $direction,
 67:             'match'     => $match,
 68:         ];
 69: 
 70:         return $this->get('zones/'.$zone_identifier.'/pagerules', $data);
 71:     }
 72: 
 73:     /**
 74:      * Page rule details [BETA] (permission needed: #zone:read)
 75:      *
 76:      * @param string $zone_identifier API item identifier tag
 77:      * @param string $identifier
 78:      */
 79:     public function details($zone_identifier, $identifier)
 80:     {
 81:         return $this->get('zones/'.$zone_identifier.'/pagerules/'.$identifier);
 82:     }
 83: 
 84:     /**
 85:      * Change a page rule [BETA] (permission needed: #zone:edit)
 86:      *
 87:      * @param string      $zone_identifier API item identifier tag
 88:      * @param string      $identifier
 89:      * @param array|null  $targets         Targets to evaluate on a request
 90:      * @param array|null  $actions         The set of actions to perform if the targets of this rule match the request.
 91:      *                                     Actions can redirect the url to another url or override settings (but not both)
 92:      * @param int|null    $priority        A number that indicates the preference for a page rule over another. In the case where
 93:      *                                     you may have a catch-all page rule (e.g., #1: '/images/') but want a rule that is more
 94:      *                                     specific to take precedence (e.g., #2: '/images/special/'), you'll want to specify a
 95:      *                                     higher priority on the latter (#2) so it will override the first.
 96:      * @param string|null $status          Status of the page rule
 97:      */
 98:     public function change($zone_identifier, $identifier, $targets = null, $actions = null, $priority = null, $status = null)
 99:     {
100:         $data = [
101:             'targets'  => $targets,
102:             'actions'  => $actions,
103:             'priority' => $priority,
104:             'status'   => $status,
105:         ];
106: 
107:         return $this->patch('zones/'.$zone_identifier.'/pagerules/'.$identifier, $data);
108:     }
109: 
110:     /**
111:      * Update a page rule [BETA] (permission needed: #zone:edit)
112:      * Replace a page rule. The final rule will exactly match the data passed with this request.
113:      *
114:      * @param string      $zone_identifier API item identifier tag
115:      * @param string      $identifier
116:      * @param array       $targets         Targets to evaluate on a request
117:      * @param array       $actions         The set of actions to perform if the targets of this rule match the request.
118:      *                                     Actions can redirect the url to another url or override settings (but not both)
119:      * @param int|null    $priority        A number that indicates the preference for a page rule over another. In the case where
120:      *                                     you may have a catch-all page rule (e.g., #1: '/images/') but want a rule that is more
121:      *                                     specific to take precedence (e.g., #2: '/images/special/'), you'll want to specify a
122:      *                                     higher priority on the latter (#2) so it will override the first.
123:      * @param string|null $status          Status of the page rule
124:      */
125:     public function update($zone_identifier, $identifier, $targets, $actions, $priority = null, $status = null)
126:     {
127:         $data = [
128:             'targets'  => $targets,
129:             'actions'  => $actions,
130:             'priority' => $priority,
131:             'status'   => $status,
132:         ];
133: 
134:         return $this->put('zones/'.$zone_identifier.'/pagerules/'.$identifier, $data);
135:     }
136: 
137:     /**
138:      * Delete a page rule [BETA] (permission needed: #zone:edit)
139:      *
140:      * @param string $zone_identifier API item identifier tag
141:      * @param string $identifier
142:      */
143:     public function delete_pagerule($zone_identifier, $identifier)
144:     {
145:         return $this->delete('zones/'.$zone_identifier.'/pagerules/'.$identifier);
146:     }
147: }
148: 
API documentation generated by ApiGen