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) |
|
|
|
|
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
|
|
|
|