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\RefreshCapable; |
17
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* LiteSpeed (OpenLiteSpeed or LiteSpeed Web Server) invalidator. |
21
|
|
|
* |
22
|
|
|
* @author Yanick Witschi <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class LiteSpeed extends HttpProxyClient implements PurgeCapable, TagCapable, ClearCapable, RefreshCapable |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function clear() |
30
|
|
|
{ |
31
|
|
|
$this->queueRequest('PURGE', $this->options['purge_endpoint'], [ |
32
|
|
|
'X-LiteSpeed-Purge' => '*', |
33
|
|
|
]); |
34
|
|
|
|
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function purge($url, array $headers = []) |
42
|
|
|
{ |
43
|
|
|
// LiteSpeed only supports purging by relative URLs |
44
|
|
|
$urlParts = parse_url($url); |
45
|
|
|
$url = array_key_exists('path', $urlParts) ? $urlParts['path'] : '/'; |
46
|
|
|
|
47
|
|
|
$this->queueRequest('PURGE', $url, $headers); |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
protected function configureOptions() |
56
|
|
|
{ |
57
|
|
|
$resolver = parent::configureOptions(); |
58
|
|
|
$resolver->setDefaults(['purge_endpoint' => '/_fos_litespeed_purge_endpoint']); |
59
|
|
|
$resolver->setAllowedTypes('purge_endpoint', 'string'); |
60
|
|
|
|
61
|
|
|
return $resolver; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function invalidateTags(array $tags) |
68
|
|
|
{ |
69
|
|
|
$this->queueRequest('PURGE', $this->options['purge_endpoint'], [ |
70
|
|
|
'X-LiteSpeed-Purge' => implode(', ', preg_filter('/^/', 'tag=', $tags)), |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function refresh($url, array $headers = []) |
80
|
|
|
{ |
81
|
|
|
$this->purge($url); |
82
|
|
|
$this->queueRequest('GET', $url, $headers); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|