1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCache package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\HttpCache\ProxyClient; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; |
15
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; |
16
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* LiteSpeed (OpenLiteSpeed or LiteSpeed Web Server) invalidator. |
20
|
|
|
* |
21
|
|
|
* @author Yanick Witschi <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class LiteSpeed extends HttpProxyClient implements PurgeCapable, TagCapable, ClearCapable |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function clear() |
29
|
|
|
{ |
30
|
|
|
$this->sendPurgeRequest([ |
31
|
|
|
'X-LiteSpeed-Purge' => '*', |
32
|
|
|
]); |
33
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function purge($url, array $headers = []) |
41
|
|
|
{ |
42
|
|
|
// LiteSpeed only supports purging by relative URLs |
43
|
|
|
$urlParts = parse_url($url); |
44
|
|
|
$url = array_key_exists('path', $urlParts) ? $urlParts['path'] : '/'; |
45
|
|
|
|
46
|
|
|
$this->sendPurgeRequest([ |
47
|
|
|
'X-LiteSpeed-Purge' => $url, |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function invalidateTags(array $tags) |
57
|
|
|
{ |
58
|
|
|
$this->sendPurgeRequest([ |
59
|
|
|
'X-LiteSpeed-Purge' => implode(', ', preg_filter('/^/', 'tag=', $tags)), |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function sendPurgeRequest(array $headers) |
66
|
|
|
{ |
67
|
|
|
// TODO: LiteSpeed is likely going to hard code this URL, otherwise it has to be configurable |
68
|
|
|
$purgeEndpoint = '/'; |
69
|
|
|
|
70
|
|
|
$this->queueRequest('PURGE', $purgeEndpoint, $headers); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|