Completed
Pull Request — master (#6)
by Richan
11:44 queued 05:32
created

ManageEtagHeader::disableEtag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace RichanFongdasen\Varnishable\Concerns;
4
5
use Symfony\Component\HttpFoundation\Response;
6
7
trait ManageEtagHeader
8
{
9
    /**
10
     * Add an ETag header to the current response.
11
     *
12
     * @param \Symfony\Component\HttpFoundation\Response $response
13
     *
14
     * @return void
15
     */
16
    protected function addEtagHeader(Response $response)
17
    {
18
        if ($this->getConfig('use_etag')) {
19
            $response->setEtag(md5($response->getContent()));
20
        }
21
    }
22
23
    /**
24
     * Disable Etag for current request.
25
     *
26
     * @return void
27
     */
28
    public function disableEtag()
29
    {
30
        $this->setConfig('use_etag', false);
31
    }
32
33
    /**
34
     * Enable Etag for current request.
35
     *
36
     * @return void
37
     */
38
    public function enableEtag()
39
    {
40
        $this->setConfig('use_etag', true);
41
    }
42
43
    /**
44
     * Get configuration value for a specific key.
45
     *
46
     * @param string $key
47
     *
48
     * @return mixed
49
     */
50
    abstract public function getConfig($key);
51
52
    /**
53
     * Set configuration value for a specific key.
54
     *
55
     * @param string $key
56
     * @param mixed  $value
57
     *
58
     * @return void
59
     */
60
    abstract public function setConfig($key, $value);
61
}
62