1: <?php
2:
3: namespace Cloudflare;
4:
5: /**
6: * CloudFlare API wrapper
7: *
8: * Zone
9: * A Zone is a domain name along with its subdomains and other identities
10: *
11: * @author James Bell <[email protected]>
12: *
13: * @version 1
14: */
15: class Zone extends Api
16: {
17: /**
18: * Default permissions level
19: *
20: * @var array
21: */
22: protected $permission_level = ['read' => '#zone:read', 'edit' => '#zone:edit'];
23:
24: /**
25: * Create a zone (permission needed: #zone:edit)
26: *
27: * @param string $domain The domain name
28: * @param bool|null $jump_start Automatically attempt to fetch existing DNS records
29: * @param int|null $organization To create a zone owned by an organization, specify the organization parameter. Organization objects can be found in the User or User's Organizations endpoints. You must pass at least the ID of the organization.
30: */
31: public function create($name, $jump_start = null, $organization = null)
32: {
33: $data = [
34: 'name' => $name,
35: 'jump_start' => $jump_start,
36: 'organization' => $organization,
37: ];
38:
39: return $this->post('zones', $data);
40: }
41:
42: /**
43: * Initiate another zone activation check (permission needed: #zone:edit)
44: *
45: * @param string $identifier API item identifier tag
46: */
47: public function activation_check($identifier)
48: {
49: return $this->put('zones/'.$identifier.'/activation_check');
50: }
51:
52: /**
53: * List zones (permission needed: #zone:read)
54: * List, search, sort, and filter your zones
55: *
56: * @param string|null $name A domain name
57: * @param string|null $status Status of the zone (active, pending, initializing, moved, deleted)
58: * @param int|null $page Page number of paginated results
59: * @param int|null $per_page Number of zones per page
60: * @param string|null $order Field to order zones by (name, status, email)
61: * @param string|null $direction Direction to order zones (asc, desc)
62: * @param string|null $match Whether to match all search requirements or at least one (any) (any, all)
63: */
64: public function zones($name = null, $status = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null)
65: {
66: $data = [
67: 'name' => $name,
68: 'status' => $status,
69: 'page' => $page,
70: 'per_page' => $per_page,
71: 'order' => $order,
72: 'direction' => $direction,
73: 'match' => $match,
74: ];
75:
76: return $this->get('zones', $data);
77: }
78:
79: /**
80: * Zone details (permission needed: #zone:read)
81: *
82: * @param string $zone_identifier API item identifier tag
83: */
84: public function zone($zone_identifier)
85: {
86: return $this->get('zones/'.$zone_identifier);
87: }
88:
89: /**
90: * Edit Vanity Name Servers (permission needed: #zone:edit)
91: *
92: * @param string $zone_identifier API item identifier tag
93: * @param array $vanity_name_servers An array of domains used for custom name servers. This is only available for Business
94: * and Enterprise plans.
95: */
96: public function edit_vanity_name_servers($zone_identifier, $vanity_name_servers)
97: {
98: $data = [
99: 'vanity_name_servers' => $vanity_name_servers,
100: ];
101:
102: return $this->patch('zones/'.$zone_identifier, $data);
103: }
104:
105: /**
106: * Edit the desired plan for the zone (permission needed: #zone:edit)
107: *
108: * @param string $zone_identifier API item identifier tag
109: * @param object $plan The desired plan for the zone. Changing this value will create/cancel associated
110: * subscriptions. To view available plans for this zone, see Zone Plans
111: */
112: public function edit_plan($zone_identifier, $plan)
113: {
114: $data = [
115: 'plan' => $plan,
116: ];
117:
118: return $this->patch('zones/'.$zone_identifier, $data);
119: }
120:
121: /**
122: * Pause all CloudFlare features (permission needed: #zone:edit)
123: * This will pause all features and settings for the zone. DNS will still resolve
124: *
125: * @param string $zone_identifier API item identifier tag
126: */
127: public function pause($zone_identifier)
128: {
129: $data = [
130: 'paused' => true,
131: ];
132:
133: return $this->patch('zones/'.$zone_identifier, $data);
134: }
135:
136: /**
137: * Re-enable all CloudFlare features (permission needed: #zone:edit)
138: * This will restore all features and settings for the zone
139: *
140: * @param string $zone_identifier API item identifier tag
141: */
142: public function unpause($zone_identifier)
143: {
144: $data = [
145: 'paused' => false,
146: ];
147:
148: return $this->patch('zones/'.$zone_identifier, $data);
149: }
150:
151: /**
152: * Delete a zone (permission needed: #zone:edit)
153: *
154: * @param string $zone_identifier API item identifier tag
155: */
156: public function delete_zone($zone_identifier)
157: {
158: return $this->delete('zones/'.$zone_identifier);
159: }
160: }
161: