1 | <?php |
||
8 | trait ManipulateHttpResponse |
||
9 | { |
||
10 | /** |
||
11 | * HTTP Request object. |
||
12 | * |
||
13 | * @var \Symfony\Component\HttpFoundation\HeaderBag |
||
14 | */ |
||
15 | protected $requestHeaders; |
||
16 | |||
17 | /** |
||
18 | * Acknowledge the ESI support and send a specific |
||
19 | * HTTP header as a reply. |
||
20 | * |
||
21 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | protected function acknowledgeEsiSupport(Response $response) |
||
33 | |||
34 | /** |
||
35 | * Add cacheable header so varnish can recognize |
||
36 | * the response as a cacheable content. |
||
37 | * |
||
38 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
39 | */ |
||
40 | protected function addCacheableHeader(Response $response) |
||
49 | |||
50 | /** |
||
51 | * Add uncacheable header so varnish can recognize |
||
52 | * the response as an uncacheable content. |
||
53 | * |
||
54 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
55 | */ |
||
56 | public function addUncacheableHeader(Response $response) |
||
60 | |||
61 | /** |
||
62 | * Normalize the cache duration value and convert |
||
63 | * it to seconds. |
||
64 | * |
||
65 | * @return int|float |
||
66 | */ |
||
67 | protected function getCacheDuration() |
||
71 | |||
72 | /** |
||
73 | * Manipulate the current Http response. |
||
74 | * |
||
75 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
76 | * |
||
77 | * @return \Symfony\Component\HttpFoundation\Response |
||
78 | */ |
||
79 | public function manipulate(Response $response) |
||
93 | |||
94 | /** |
||
95 | * Set cache duration value in minutes. This value will |
||
96 | * be added to the HTTP response's Cache-Control header. |
||
97 | * |
||
98 | * @param int $duration [Cache duration value in minutes] |
||
99 | */ |
||
100 | public function setCacheDuration($duration) |
||
104 | |||
105 | /** |
||
106 | * Set the current Http request headers. |
||
107 | * |
||
108 | * @param \Symfony\Component\HttpFoundation\HeaderBag $headers |
||
109 | */ |
||
110 | public function setRequestHeaders(HeaderBag $headers) |
||
114 | |||
115 | /** |
||
116 | * Check if the current response shouldn't be cached. |
||
117 | * |
||
118 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
119 | * |
||
120 | * @return string|array |
||
121 | */ |
||
122 | protected function shouldNotCache(Response $response) |
||
126 | |||
127 | /** |
||
128 | * Add an ETag header to the current response. |
||
129 | * |
||
130 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | abstract protected function addEtagHeader(Response $response); |
||
135 | |||
136 | /** |
||
137 | * Add Last-Modified header to the current response. |
||
138 | * |
||
139 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | abstract protected function addLastModifiedHeader(Response $response); |
||
144 | |||
145 | /** |
||
146 | * Get configuration value for a specific key. |
||
147 | * |
||
148 | * @param string $key |
||
149 | * |
||
150 | * @return mixed |
||
151 | */ |
||
152 | abstract public function getConfig($key); |
||
153 | |||
154 | /** |
||
155 | * Set configuration value for a specific key. |
||
156 | * |
||
157 | * @param string $key |
||
158 | * @param mixed $value |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | abstract public function setConfig($key, $value); |
||
163 | } |
||
164 |