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

RefreshListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A handleRefresh() 0 14 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