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\HttpFoundation\Request; |
||
15 | use Symfony\Component\HttpFoundation\Response; |
||
16 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
||
17 | use Symfony\Contracts\EventDispatcher\Event as BaseEvent; |
||
18 | |||
19 | /** |
||
20 | * Event raised by the HttpCache kernel. |
||
21 | * |
||
22 | * @author David Buchmann <[email protected]> |
||
23 | */ |
||
24 | class CacheEvent extends BaseEvent |
||
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 | * |
||
49 | * @param CacheInvalidation $kernel the kernel raising with this event |
||
50 | * @param Request $request the request being processed |
||
51 | * @param Response|null $response the response, if available |
||
52 | * @param int $requestType the request type (default HttpKernelInterface::MASTER_REQUEST) |
||
53 | */ |
||
54 | 46 | public function __construct(CacheInvalidation $kernel, Request $request, Response $response = null, $requestType = HttpKernelInterface::MASTER_REQUEST) |
|
0 ignored issues
–
show
|
|||
55 | { |
||
56 | 46 | $this->kernel = $kernel; |
|
57 | 46 | $this->request = $request; |
|
58 | 46 | $this->response = $response; |
|
59 | 46 | $this->requestType = $requestType; |
|
60 | 46 | } |
|
61 | |||
62 | /** |
||
63 | * Get the cache kernel that raised this event. |
||
64 | * |
||
65 | * @return CacheInvalidation |
||
66 | */ |
||
67 | 22 | public function getKernel() |
|
68 | { |
||
69 | 22 | return $this->kernel; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Get the request that is being processed. |
||
74 | * |
||
75 | * @return Request |
||
76 | */ |
||
77 | 34 | public function getRequest() |
|
78 | { |
||
79 | 34 | return $this->request; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * One of the constants HttpKernelInterface::MASTER_REQUEST or SUB_REQUEST. |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | 1 | public function getRequestType() |
|
88 | { |
||
89 | 1 | return $this->requestType; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * 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 | * |
||
96 | * @return Response|null the response if one was set |
||
97 | */ |
||
98 | 45 | public function getResponse() |
|
99 | { |
||
100 | 45 | 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 | 15 | public function setResponse(Response $response) |
|
109 | { |
||
110 | 15 | $this->response = $response; |
|
111 | |||
112 | 15 | $this->stopPropagation(); |
|
113 | 15 | } |
|
114 | } |
||
115 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.