1 | <?php |
||
43 | trait EventDispatchingHttpCache |
||
44 | { |
||
45 | /** |
||
46 | * @var EventDispatcherInterface |
||
47 | */ |
||
48 | private $eventDispatcher; |
||
49 | |||
50 | /** |
||
51 | * Get event dispatcher. |
||
52 | * |
||
53 | * @return EventDispatcherInterface |
||
54 | */ |
||
55 | 10 | public function getEventDispatcher() |
|
63 | |||
64 | /** |
||
65 | * Add an event subscriber. |
||
66 | * |
||
67 | * @see EventDispatcherInterface::addSubscriber |
||
68 | */ |
||
69 | 9 | public function addSubscriber(EventSubscriberInterface $subscriber) |
|
73 | |||
74 | /** |
||
75 | * Add an event listener to this HttpCache. |
||
76 | * |
||
77 | * @see EventDispatcherInterface::addListener |
||
78 | */ |
||
79 | 1 | public function addListener($eventName, $listener, $priority = 0) |
|
80 | { |
||
81 | 1 | $this->getEventDispatcher()->addListener($eventName, $listener, $priority); |
|
82 | 1 | } |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | * |
||
87 | * Adding the Events::PRE_HANDLE and Events::POST_HANDLE events. |
||
88 | */ |
||
89 | 4 | public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | * |
||
106 | * Trigger event to alter response before storing it in the cache. |
||
107 | */ |
||
108 | 2 | protected function store(Request $request, Response $response) |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | * |
||
118 | * Adding the Events::PRE_INVALIDATE event. |
||
119 | */ |
||
120 | 2 | protected function invalidate(Request $request, $catch = false) |
|
128 | |||
129 | /** |
||
130 | * Dispatch an event if needed. |
||
131 | * |
||
132 | * @param string $name Name of the event to trigger. One of the constants in FOS\HttpCache\SymfonyCache\Events |
||
133 | * @param Request $request |
||
134 | * @param Response|null $response If already available |
||
135 | * |
||
136 | * @return Response The response to return, which might be provided/altered by a listener |
||
137 | */ |
||
138 | 10 | protected function dispatch($name, Request $request, Response $response = null) |
|
148 | } |
||
149 |