Completed
Push — master ( e9c672...2c6f31 )
by David de
05:18
created

RefreshListener::handleRefresh()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 2
nop 1
crap 4
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\SymfonyCache;
13
14
/**
15
 * Refresh handler for the symfony built-in HttpCache.
16
 *
17
 * To use this handler, make sure that your HttpCache makes the fetch method
18
 * public.
19
 *
20
 * @author David Buchmann <[email protected]>
21
 *
22
 * {@inheritdoc}
23
 */
24
class RefreshListener extends AccessControlledListener
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public static function getSubscribedEvents()
30
    {
31
        return [
32 1
            Events::PRE_HANDLE => 'handleRefresh',
33 1
        ];
34
    }
35
36
    /**
37
     * Look at safe requests and handle refresh requests.
38
     *
39
     * Ignore refresh to let normal lookup happen when the request comes from
40
     * a non-authorized client.
41
     *
42
     * @param CacheEvent $event
43
     */
44 6
    public function handleRefresh(CacheEvent $event)
45
    {
46 6
        $request = $event->getRequest();
47 6
        if (!$request->isMethodSafe()
48 6
            || !$request->isNoCache()
49 5
            || !$this->isRequestAllowed($request)
50 6
        ) {
51 5
            return;
52
        }
53
54 1
        $event->setResponse(
55 1
            $event->getKernel()->fetch($request)
56 1
        );
57 1
    }
58
}
59