Skip to content

Commit a4ddb61

Browse files
authored
Merge pull request #7 from cloudflare/COM-40
COM-40 :: Added Page Rules endpoint.
2 parents 1658f4a + 3166645 commit a4ddb61

File tree

7 files changed

+833
-3
lines changed

7 files changed

+833
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Each API call is provided via a similarly named function within various classes
1616
- [x] Zones
1717
- [x] User Administration (partial)
1818
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
19-
- [ ] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
19+
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
2020
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
2121
- [ ] Virtual DNS Management
2222
- [ ] Custom hostnames
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: junade
5+
* Date: 19/09/2017
6+
* Time: 16:57
7+
*/
8+
9+
namespace Cloudflare\API\Configurations;
10+
11+
12+
class ConfigurationsException extends \Exception
13+
{
14+
15+
}
Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: junade
5+
* Date: 19/09/2017
6+
* Time: 16:50
7+
*/
8+
9+
namespace Cloudflare\API\Configurations;
10+
11+
class PageRulesActions implements Configurations
12+
{
13+
private $configs = array();
14+
15+
public function setAlwaysOnline(bool $active)
16+
{
17+
$object = new \stdClass();
18+
$object->id = "always_online";
19+
$object->value = $active === true ? "on" : "off";
20+
21+
array_push($this->configs, $object);
22+
}
23+
24+
public function setAlwaysUseHTTPS(bool $active)
25+
{
26+
$object = new \stdClass();
27+
$object->id = "always_use_https";
28+
$object->value = $active === true ? "on" : "off";
29+
30+
array_push($this->configs, $object);
31+
}
32+
33+
public function setBrowserCacheTTL(int $ttl)
34+
{
35+
$object = new \stdClass();
36+
$object->id = "browser_cache_ttl";
37+
$object->value = $ttl;
38+
39+
array_push($this->configs, $object);
40+
}
41+
42+
public function setBrowserIntegrityCheck(bool $active)
43+
{
44+
$object = new \stdClass();
45+
$object->id = "browser_check";
46+
$object->value = $active === true ? "on" : "off";
47+
48+
array_push($this->configs, $object);
49+
}
50+
51+
public function setBypassCacheOnCookie(bool $value)
52+
{
53+
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
54+
throw new ConfigurationsException("Invalid cookie string.");
55+
}
56+
57+
$object = new \stdClass();
58+
$object->id = "bypass_cache_on_cookie";
59+
$object->value = $value;
60+
61+
array_push($this->configs, $object);
62+
}
63+
64+
public function setCacheByDeviceType(bool $active)
65+
{
66+
$object = new \stdClass();
67+
$object->id = "cache_by_device_type";
68+
$object->value = $active === true ? "on" : "off";
69+
70+
array_push($this->configs, $object);
71+
}
72+
73+
public function setCacheKey(string $value)
74+
{
75+
$object = new \stdClass();
76+
$object->id = "cache_key";
77+
$object->value = $value;
78+
79+
array_push($this->configs, $object);
80+
}
81+
82+
public function setCacheLevel(string $value)
83+
{
84+
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
85+
throw new ConfigurationsException("Invalid cache level");
86+
}
87+
88+
$object = new \stdClass();
89+
$object->id = "cache_level";
90+
$object->value = $value;
91+
92+
array_push($this->configs, $object);
93+
}
94+
95+
public function setCacheOnCookie(bool $value)
96+
{
97+
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
98+
throw new ConfigurationsException("Invalid cookie string.");
99+
}
100+
101+
$object = new \stdClass();
102+
$object->id = "cache_on_cookie";
103+
$object->value = $value;
104+
105+
array_push($this->configs, $object);
106+
}
107+
108+
public function setDisableApps(bool $active)
109+
{
110+
$object = new \stdClass();
111+
$object->id = "disable_apps";
112+
$object->value = $active === true ? "on" : "off";
113+
114+
array_push($this->configs, $object);
115+
}
116+
117+
public function setDisablePerformance(bool $active)
118+
{
119+
$object = new \stdClass();
120+
$object->id = "disable_performance";
121+
$object->value = $active === true ? "on" : "off";
122+
123+
array_push($this->configs, $object);
124+
}
125+
126+
public function setDisableSecurity(bool $active)
127+
{
128+
$object = new \stdClass();
129+
$object->id = "disable_security";
130+
$object->value = $active === true ? "on" : "off";
131+
132+
array_push($this->configs, $object);
133+
}
134+
135+
public function setEdgeCacheTTL(int $value)
136+
{
137+
if ($value > 2419200) {
138+
throw new ConfigurationsException("Edge Cache TTL too high.");
139+
}
140+
141+
$object = new \stdClass();
142+
$object->id = "edge_cache_ttl";
143+
$object->value = $value;
144+
145+
array_push($this->configs, $object);
146+
}
147+
148+
public function setEmailObfuscation(bool $active)
149+
{
150+
$object = new \stdClass();
151+
$object->id = "disable_security";
152+
$object->value = $active === true ? "on" : "off";
153+
154+
array_push($this->configs, $object);
155+
}
156+
157+
public function setForwardingURL(int $statusCode, string $forwardingUrl)
158+
{
159+
if (in_array($statusCode, ['301', '302'])) {
160+
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
161+
}
162+
163+
$object = new \stdClass();
164+
$object->id = "forwarding_url";
165+
$object->status_code = $statusCode;
166+
$object->url = $forwardingUrl;
167+
168+
array_push($this->configs, $object);
169+
}
170+
171+
public function setHostHeaderOverride(bool $active)
172+
{
173+
$object = new \stdClass();
174+
$object->id = "host_header_override";
175+
$object->value = $active === true ? "on" : "off";
176+
177+
array_push($this->configs, $object);
178+
}
179+
180+
public function setHotlinkProtection(bool $active)
181+
{
182+
$object = new \stdClass();
183+
$object->id = "hotlink_protection";
184+
$object->value = $active === true ? "on" : "off";
185+
186+
array_push($this->configs, $object);
187+
}
188+
189+
public function setIPGeoLocationHeader(bool $active)
190+
{
191+
$object = new \stdClass();
192+
$object->id = "ip_geolocation";
193+
$object->value = $active === true ? "on" : "off";
194+
195+
array_push($this->configs, $object);
196+
}
197+
198+
public function setMinification(bool $html, bool $css, bool $js)
199+
{
200+
$object = new \stdClass();
201+
$object->id = "minification";
202+
$object->html = $html === true ? "on" : "off";
203+
$object->css = $css === true ? "on" : "off";
204+
$object->js = $js === true ? "on" : "off";
205+
206+
array_push($this->configs, $object);
207+
}
208+
209+
public function setMirage(bool $active)
210+
{
211+
$object = new \stdClass();
212+
$object->id = "mirage";
213+
$object->value = $active === true ? "on" : "off";
214+
215+
array_push($this->configs, $object);
216+
}
217+
218+
public function setOriginErrorPagePassthru(bool $active)
219+
{
220+
$object = new \stdClass();
221+
$object->id = "origin_error_page_pass_thru";
222+
$object->value = $active === true ? "on" : "off";
223+
224+
array_push($this->configs, $object);
225+
}
226+
227+
public function setQueryStringSort(bool $active)
228+
{
229+
$object = new \stdClass();
230+
$object->id = "sort_query_string_for_cache";
231+
$object->value = $active === true ? "on" : "off";
232+
233+
array_push($this->configs, $object);
234+
}
235+
236+
public function setDisableRailgun(bool $active)
237+
{
238+
$object = new \stdClass();
239+
$object->id = "disable_railgun";
240+
$object->value = $active === true ? "on" : "off";
241+
242+
array_push($this->configs, $object);
243+
}
244+
245+
public function setResolveOverride(bool $value)
246+
{
247+
$object = new \stdClass();
248+
$object->id = "resolve_override";
249+
$object->value = $value;
250+
251+
array_push($this->configs, $object);
252+
}
253+
254+
public function setRespectStrongEtag(bool $active)
255+
{
256+
$object = new \stdClass();
257+
$object->id = "respect_strong_etag";
258+
$object->value = $active === true ? "on" : "off";
259+
260+
array_push($this->configs, $object);
261+
}
262+
263+
public function setResponseBuffering(bool $active)
264+
{
265+
$object = new \stdClass();
266+
$object->id = "response_buffering";
267+
$object->value = $active === true ? "on" : "off";
268+
269+
array_push($this->configs, $object);
270+
}
271+
272+
public function setRocketLoader(string $value)
273+
{
274+
if (!in_array($value, ["off", "manual", "automatic"])) {
275+
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
276+
}
277+
278+
$object = new \stdClass();
279+
$object->id = "rocket_loader";
280+
$object->value = $value;
281+
282+
array_push($this->configs, $object);
283+
}
284+
285+
public function setSecurityLevel(string $value)
286+
{
287+
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
288+
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
289+
}
290+
291+
$object = new \stdClass();
292+
$object->id = "security_level";
293+
$object->value = $value;
294+
295+
array_push($this->configs, $object);
296+
}
297+
298+
public function setServerSideExcludes(bool $active)
299+
{
300+
$object = new \stdClass();
301+
$object->id = "server_side_exclude";
302+
$object->value = $active === true ? "on" : "off";
303+
304+
array_push($this->configs, $object);
305+
}
306+
307+
public function setSmartErrors(bool $active)
308+
{
309+
$object = new \stdClass();
310+
$object->id = "smart_errors";
311+
$object->value = $active === true ? "on" : "off";
312+
313+
array_push($this->configs, $object);
314+
}
315+
316+
public function setSSL(string $value)
317+
{
318+
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
319+
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
320+
}
321+
322+
$object = new \stdClass();
323+
$object->id = "smart_errors";
324+
$object->value = $value;
325+
326+
array_push($this->configs, $object);
327+
}
328+
329+
public function setTrueClientIpHeader(bool $active)
330+
{
331+
$object = new \stdClass();
332+
$object->id = "true_client_ip_header";
333+
$object->value = $active === true ? "on" : "off";
334+
335+
array_push($this->configs, $object);
336+
}
337+
338+
public function setWAF(bool $active)
339+
{
340+
$object = new \stdClass();
341+
$object->id = "waf";
342+
$object->value = $active === true ? "on" : "off";
343+
344+
array_push($this->configs, $object);
345+
}
346+
347+
public function setAutomatedHTTPSRewrites(bool $active)
348+
{
349+
$object = new \stdClass();
350+
$object->id = "automatic_https_rewrites";
351+
$object->value = $active === true ? "on" : "off";
352+
353+
array_push($this->configs, $object);
354+
}
355+
356+
public function setOpportunisticEncryption(bool $active)
357+
{
358+
$object = new \stdClass();
359+
$object->id = "opportunistic_encryption";
360+
$object->value = $active === true ? "on" : "off";
361+
362+
array_push($this->configs, $object);
363+
}
364+
365+
public function getArray(): array
366+
{
367+
return $this->configs;
368+
}
369+
}

0 commit comments

Comments
 (0)