1 | <?php |
||
8 | trait InvalidateVarnishCache |
||
9 | { |
||
10 | /** |
||
11 | * Flush entire cache for an application hostname. |
||
12 | * |
||
13 | * @param string $hostname |
||
14 | * |
||
15 | * @throws Exception |
||
16 | * |
||
17 | * @return void |
||
18 | */ |
||
19 | public function flush(string $hostname): void |
||
25 | |||
26 | /** |
||
27 | * Generate ban request for an application hostname, |
||
28 | * specified by a regular expression. |
||
29 | * |
||
30 | * @param string $hostname |
||
31 | * @param string $pattern |
||
32 | * |
||
33 | * @throws Exception |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | public function banByPattern(string $hostname, string $pattern): void |
||
44 | |||
45 | /** |
||
46 | * Generate ban request for an application hostname, |
||
47 | * specified by a set of regular expression. |
||
48 | * |
||
49 | * @param string $hostname |
||
50 | * @param array $patterns |
||
51 | * |
||
52 | * @throws Exception |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | public function banByPatterns(string $hostname, array $patterns): void |
||
62 | |||
63 | /** |
||
64 | * Generate ban request for an application hostname, |
||
65 | * specified by a single urls. |
||
66 | * |
||
67 | * @param string $hostname |
||
68 | * @param string $url |
||
69 | * |
||
70 | * @throws Exception |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function banByUrl(string $hostname, string $url): void |
||
81 | |||
82 | /** |
||
83 | * Generate ban request for an application hostname, |
||
84 | * specified by a set of urls. |
||
85 | * |
||
86 | * @param string $hostname |
||
87 | * @param array $urls |
||
88 | * |
||
89 | * @throws Exception |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | public function banByUrls(string $hostname, array $urls): void |
||
99 | |||
100 | /** |
||
101 | * Get a valid varnish host url to send the |
||
102 | * ban request. |
||
103 | * |
||
104 | * @param string $varnishHost |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | protected function getVarnishUrl(string $varnishHost): string |
||
112 | |||
113 | /** |
||
114 | * Send the ban request to every varnish hosts. |
||
115 | * |
||
116 | * @param array $headers |
||
117 | * @param string $method |
||
118 | * |
||
119 | * @throws Exception |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | protected function sendBanRequest(array $headers, string $method = 'BAN'): void |
||
133 | |||
134 | /** |
||
135 | * Get configuration value for a specific key. |
||
136 | * |
||
137 | * @param string $key |
||
138 | * |
||
139 | * @return mixed |
||
140 | */ |
||
141 | abstract public function getConfig($key); |
||
142 | |||
143 | /** |
||
144 | * Get guzzle client object. |
||
145 | * |
||
146 | * @return \GuzzleHttp\Client |
||
147 | */ |
||
148 | abstract public function getGuzzle(): Client; |
||
149 | } |
||
150 |