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\HttpKernelInterface; |
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
|
|
|
* @var int |
43
|
|
|
*/ |
44
|
|
|
private $requestType; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Make sure your $kernel implements CacheInvalidationInterface. |
48
|
41 |
|
* |
49
|
|
|
* @param CacheInvalidation $kernel the kernel raising with this event |
50
|
41 |
|
* @param Request $request the request being processed |
51
|
41 |
|
* @param Response $response the response, if available |
52
|
41 |
|
* @param int $requestType the request type (default HttpKernelInterface::MASTER_REQUEST) |
53
|
41 |
|
*/ |
54
|
|
|
public function __construct(CacheInvalidation $kernel, Request $request, Response $response = null, $requestType = HttpKernelInterface::MASTER_REQUEST) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$this->kernel = $kernel; |
57
|
|
|
$this->request = $request; |
58
|
|
|
$this->response = $response; |
59
|
|
|
$this->requestType = $requestType; |
60
|
19 |
|
} |
61
|
|
|
|
62
|
19 |
|
/** |
63
|
|
|
* Get the cache kernel that raised this event. |
64
|
|
|
* |
65
|
|
|
* @return CacheInvalidation |
66
|
|
|
*/ |
67
|
|
|
public function getKernel() |
68
|
|
|
{ |
69
|
|
|
return $this->kernel; |
70
|
31 |
|
} |
71
|
|
|
|
72
|
31 |
|
/** |
73
|
|
|
* Get the request that is being processed. |
74
|
|
|
* |
75
|
|
|
* @return Request |
76
|
|
|
*/ |
77
|
|
|
public function getRequest() |
78
|
|
|
{ |
79
|
|
|
return $this->request; |
80
|
|
|
} |
81
|
40 |
|
|
82
|
|
|
/** |
83
|
40 |
|
* One of the constants HttpKernelInterface::MASTER_REQUEST or SUB_REQUEST. |
84
|
|
|
* |
85
|
|
|
* @return int |
86
|
|
|
*/ |
87
|
|
|
public function getRequestType() |
88
|
|
|
{ |
89
|
|
|
return $this->requestType; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
14 |
|
* Events that occur after the response is created provide the default response. |
94
|
|
|
* Event listeners can also set the response to make it available here. |
95
|
14 |
|
* |
96
|
|
|
* @return Response|null the response if one was set |
97
|
14 |
|
*/ |
98
|
14 |
|
public function getResponse() |
99
|
|
|
{ |
100
|
|
|
return $this->response; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets a response to use instead of continuing to handle this request. |
105
|
|
|
* |
106
|
|
|
* Setting a response stops propagation of the event to further event handlers. |
107
|
|
|
* |
108
|
|
|
* @param Response $response |
109
|
|
|
*/ |
110
|
|
|
public function setResponse(Response $response) |
111
|
|
|
{ |
112
|
|
|
$this->response = $response; |
113
|
|
|
|
114
|
|
|
$this->stopPropagation(); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|