-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEsiSubscriber.php
49 lines (41 loc) · 1.18 KB
/
EsiSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Drupal\esi_placeholders\EventSubscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EsiSubscriber implements EventSubscriberInterface
{
/**
* @var Symfony\Component\HttpKernel\HttpCache\Esi
*/
protected $esi;
/**
* @param Symfony\Component\HttpKernel\HttpCache\Esi $esi
*/
public function __construct(Esi $esi)
{
$this->esi = $esi;
}
/**
* @param FilterResponseEvent $event
* @return \Symfony\Component\HttpFoundation\Response
*/
public function onRespond(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if($this->esi->hasSurrogateCapability($request)){
$this->esi->addSurrogateControl($response);
return $response;
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
$events[KernelEvents::RESPONSE][] = ['onRespond', -10000];
return $events;
}
}