Skip to content

Commit 25cf2d9

Browse files
committed
Fixed missing request type in event
1 parent 8676d82 commit 25cf2d9

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/SymfonyCache/CacheEvent.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\EventDispatcher\Event;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\KernelInterface;
1718

1819
/**
1920
* Event raised by the HttpCache kernel.
@@ -37,18 +38,25 @@ class CacheEvent extends Event
3738
*/
3839
private $response;
3940

41+
/**
42+
* @var int
43+
*/
44+
private $requestType;
45+
4046
/**
4147
* Make sure your $kernel implements CacheInvalidationInterface.
4248
*
43-
* @param CacheInvalidation $kernel the kernel raising with this event
44-
* @param Request $request the request being processed
45-
* @param Response $response the response, if available
49+
* @param CacheInvalidation $kernel the kernel raising with this event
50+
* @param Request $request the request being processed
51+
* @param Response $response the response, if available
52+
* @param int $requestType the request type (default KernelInterface::MASTER_REQUEST)
4653
*/
47-
public function __construct(CacheInvalidation $kernel, Request $request, Response $response = null)
54+
public function __construct(CacheInvalidation $kernel, Request $request, Response $response = null, $requestType = KernelInterface::MASTER_REQUEST)
4855
{
4956
$this->kernel = $kernel;
5057
$this->request = $request;
5158
$this->response = $response;
59+
$this->requestType = $requestType;
5260
}
5361

5462
/**
@@ -71,6 +79,16 @@ public function getRequest()
7179
return $this->request;
7280
}
7381

82+
/**
83+
* Get the request type.
84+
*
85+
* @return int
86+
*/
87+
public function getRequestType()
88+
{
89+
return $this->requestType;
90+
}
91+
7492
/**
7593
* Events that occur after the response is created provide the default response.
7694
* Event listeners can also set the response to make it available here.

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\Response;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
20+
use Symfony\Component\HttpKernel\KernelInterface;
2021

2122
/**
2223
* Trait for enhanced Symfony reverse proxy based on the symfony kernel component.
@@ -91,13 +92,13 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
9192
// trigger loading the CacheEvent to avoid fatal error when HttpKernel::loadClassCache is used.
9293
class_exists(CacheEvent::class);
9394

94-
if ($response = $this->dispatch(Events::PRE_HANDLE, $request)) {
95-
return $this->dispatch(Events::POST_HANDLE, $request, $response);
95+
if ($response = $this->dispatch(Events::PRE_HANDLE, $request, null, $type)) {
96+
return $this->dispatch(Events::POST_HANDLE, $request, $response, $type);
9697
}
9798

9899
$response = parent::handle($request, $type, $catch);
99100

100-
return $this->dispatch(Events::POST_HANDLE, $request, $response);
101+
return $this->dispatch(Events::POST_HANDLE, $request, $response, $type);
101102
}
102103

103104
/**
@@ -129,16 +130,17 @@ protected function invalidate(Request $request, $catch = false)
129130
/**
130131
* Dispatch an event if needed.
131132
*
132-
* @param string $name Name of the event to trigger. One of the constants in FOS\HttpCache\SymfonyCache\Events
133+
* @param string $name Name of the event to trigger. One of the constants in FOS\HttpCache\SymfonyCache\Events
133134
* @param Request $request
134-
* @param Response|null $response If already available
135+
* @param Response|null $response If already available
136+
* @param int $requestType The request type (default KernelInterface::MASTER_REQUEST)
135137
*
136138
* @return Response The response to return, which might be provided/altered by a listener
137139
*/
138-
protected function dispatch($name, Request $request, Response $response = null)
140+
protected function dispatch($name, Request $request, Response $response = null, $requestType = KernelInterface::MASTER_REQUEST)
139141
{
140142
if ($this->getEventDispatcher()->hasListeners($name)) {
141-
$event = new CacheEvent($this, $request, $response);
143+
$event = new CacheEvent($this, $request, $response, $requestType);
142144
$this->getEventDispatcher()->dispatch($name, $event);
143145
$response = $event->getResponse();
144146
}

0 commit comments

Comments
 (0)