|
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\Exception\InvalidArgumentException; |
|
15
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; |
|
16
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; |
|
17
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; |
|
18
|
|
|
use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Fastly HTTP cache invalidator. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Simone Fumagalli <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class Fastly extends HttpProxyClient implements TagCapable |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function invalidateTags(array $tags) |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
$headers = [ |
|
36
|
|
|
'Fastly-Key' => $this->options['authentication_token'], |
|
37
|
|
|
'Accept' => 'application/json' |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
if (true === $this->options['soft_purge']) { |
|
41
|
|
|
$headers['Fastly-Soft-Purge'] = 1; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
foreach (\explode(",", $this->options['service_identifier']) as $fastlyServiceId) { |
|
45
|
|
|
foreach ($tags as $tag) { |
|
46
|
|
|
$this->queueRequest( |
|
47
|
|
|
Request::METHOD_POST, |
|
48
|
|
|
sprintf("/service/%s/purge/%s", $fastlyServiceId, $tag), |
|
49
|
|
|
$headers, |
|
50
|
|
|
false |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function configureOptions() |
|
62
|
|
|
{ |
|
63
|
|
|
$resolver = parent::configureOptions(); |
|
64
|
|
|
|
|
65
|
|
|
$resolver->setRequired([ |
|
66
|
|
|
'authentication_token', |
|
67
|
|
|
'service_identifier', |
|
68
|
|
|
'soft_purge' |
|
69
|
|
|
]); |
|
70
|
|
|
|
|
71
|
|
|
$resolver->setDefaults([ |
|
72
|
|
|
'soft_purge' => true, |
|
73
|
|
|
]); |
|
74
|
|
|
|
|
75
|
|
|
return $resolver; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|