Completed
Pull Request — master (#403)
by Simone
06:03
created

Fastly   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidateTags() 0 18 3
A configureOptions() 0 16 1
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 ($tags as $tag) {
45
            $this->queueRequest(Request::METHOD_POST, sprintf("/service/%s/purge/%s", $this->options['service_identifier'], $tag), $headers, false);
46
        }
47
48
        return $this;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function configureOptions()
55
    {
56
        $resolver = parent::configureOptions();
57
58
        $resolver->setRequired([
59
            'authentication_token',
60
            'service_identifier',
61
            'soft_purge'
62
        ]);
63
64
        $resolver->setDefaults([
65
            'soft_purge' => true,
66
        ]);
67
68
        return $resolver;
69
    }
70
71
}
72