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 | * @param int $cacheDuration |
||
40 | */ |
||
41 | protected function addCacheableHeader(Response $response, $cacheDuration) |
||
50 | |||
51 | /** |
||
52 | * Add uncacheable header so varnish can recognize |
||
53 | * the response as an uncacheable content. |
||
54 | * |
||
55 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
56 | */ |
||
57 | public function addUncacheableHeader(Response $response) |
||
61 | |||
62 | /** |
||
63 | * Normalize the given cache duration and convert |
||
64 | * it to seconds. |
||
65 | * |
||
66 | * @param int $duration |
||
67 | * |
||
68 | * @return int|float |
||
69 | */ |
||
70 | protected function getCacheDuration($duration) |
||
76 | |||
77 | /** |
||
78 | * Manipulate the current Http response. |
||
79 | * |
||
80 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
81 | * @param int $cacheDuration |
||
82 | * |
||
83 | * @return \Symfony\Component\HttpFoundation\Response |
||
84 | */ |
||
85 | public function manipulate(Response $response, $cacheDuration) |
||
99 | |||
100 | /** |
||
101 | * Set the current Http request headers. |
||
102 | * |
||
103 | * @param \Symfony\Component\HttpFoundation\HeaderBag $headers |
||
104 | */ |
||
105 | public function setRequestHeaders(HeaderBag $headers) |
||
109 | |||
110 | /** |
||
111 | * Check if the current response shouldn't be cached. |
||
112 | * |
||
113 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
114 | * |
||
115 | * @return string|array |
||
116 | */ |
||
117 | protected function shouldNotCache(Response $response) |
||
121 | |||
122 | /** |
||
123 | * Add an ETag header to the current response. |
||
124 | * |
||
125 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | abstract protected function addEtagHeader(Response $response); |
||
130 | |||
131 | /** |
||
132 | * Add Last-Modified header to the current response. |
||
133 | * |
||
134 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | abstract protected function addLastModifiedHeader(Response $response); |
||
139 | |||
140 | /** |
||
141 | * Get configuration value for a specific key. |
||
142 | * |
||
143 | * @param string $key |
||
144 | * |
||
145 | * @return mixed |
||
146 | */ |
||
147 | abstract public function getConfig($key); |
||
148 | } |
||
149 |