Completed
Pull Request — master (#364)
by Alessandro
04:31
created

CacheEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 76
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getKernel() 0 4 1
A getRequest() 0 4 1
A getResponse() 0 4 1
A setResponse() 0 6 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\SymfonyCache;
13
14
use Symfony\Component\EventDispatcher\Event;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
18
19
/**
20
 * Event raised by the HttpCache kernel.
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24
class CacheEvent extends Event
25
{
26
    /**
27
     * @var CacheInvalidation
28
     */
29
    private $kernel;
30
31
    /**
32
     * @var Request
33
     */
34
    private $request;
35
36
    /**
37
     * @var Response
38
     */
39
    private $response;
40
41
    /**
42
     * Make sure your $kernel implements CacheInvalidationInterface.
43
     *
44
     * @param CacheInvalidation $kernel   The kernel raising with this event
45
     * @param Request           $request  The request being processed
46
     * @param Response          $response The response, if available
47
     */
48
    public function __construct(CacheInvalidation $kernel, Request $request, Response $response = null)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
49
    {
50
        $this->kernel = $kernel;
51
        $this->request = $request;
52
        $this->response = $response;
53
    }
54
55
    /**
56
     * Get the cache kernel that raised this event.
57
     *
58
     * @return CacheInvalidation
59
     */
60
    public function getKernel()
61
    {
62
        return $this->kernel;
63
    }
64
65
    /**
66
     * Get the request that is being processed.
67
     *
68
     * @return Request
69
     */
70
    public function getRequest()
71
    {
72
        return $this->request;
73
    }
74
75
    /**
76
     * Events that occur after the response is created provide the default response.
77
     * Event listeners can also set the response to make it available here.
78
     *
79
     * @return Response|null The response if one was set
80
     */
81
    public function getResponse()
82
    {
83
        return $this->response;
84
    }
85
86
    /**
87
     * Sets a response to use instead of continuing to handle this request.
88
     *
89
     * Setting a response stops propagation of the event to further event handlers.
90
     *
91
     * @param Response $response
92
     */
93
    public function setResponse(Response $response)
94
    {
95
        $this->response = $response;
96
97
        $this->stopPropagation();
98
    }
99
}
100