1 | <?php |
||
14 | class ResponseCacheControl extends CacheControl |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | protected static $directiveMethods = [ |
||
20 | 'public' => 'withPublic', |
||
21 | 'private' => 'withPrivate', |
||
22 | 's-maxage' => 'withSharedMaxAge', |
||
23 | 'stale-while-revalidate' => 'withStaleWhileRevalidate', |
||
24 | 'stale-if-error' => 'withStaleIfError', |
||
25 | 'must-revalidate' => 'withMustRevalidate', |
||
26 | 'proxy-revalidate' => 'withProxyRevalidate', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Create a new Response Cache-Control object from a header string. |
||
31 | * |
||
32 | * @param string $string |
||
33 | * @return static |
||
34 | */ |
||
35 | 1 | public static function fromString($string) |
|
39 | |||
40 | /** |
||
41 | * Set whether a response should be cached by shared caches. The method will automatically |
||
42 | * remove the private flag if it is set. |
||
43 | * |
||
44 | * @param bool $flag |
||
45 | * @return static |
||
46 | */ |
||
47 | 4 | public function withPublic($flag = true) |
|
51 | |||
52 | /** |
||
53 | * @return bool |
||
54 | */ |
||
55 | 1 | public function isPublic() |
|
59 | |||
60 | /** |
||
61 | * Set whether a response should be private (only cacheable by the client who made the request. |
||
62 | * The method will automatically remove the public flag if it is set. |
||
63 | * |
||
64 | * @param bool $flag |
||
65 | * @return static |
||
66 | */ |
||
67 | 4 | public function withPrivate($flag = true) |
|
71 | |||
72 | /** |
||
73 | * @return bool |
||
74 | */ |
||
75 | 1 | public function isPrivate() |
|
79 | |||
80 | /** |
||
81 | * Set how many seconds shared caches should cache the response. Use this directive only if it |
||
82 | * is different than the max age value. |
||
83 | * |
||
84 | * @param int $seconds |
||
85 | * @return static |
||
86 | */ |
||
87 | 1 | public function withSharedMaxAge($seconds) |
|
91 | |||
92 | /** |
||
93 | * @return int|null |
||
94 | */ |
||
95 | 1 | public function getSharedMaxAge() |
|
99 | |||
100 | /** |
||
101 | * Returns the number of seconds the response should be cached. The method returns the shared |
||
102 | * max age if available and the normal max age otherwise. If both directives are not available, |
||
103 | * the method returns `null`. |
||
104 | * |
||
105 | * @return int|null Lifetime in seconds if available, null otherwise |
||
106 | */ |
||
107 | 4 | public function getLifetime() |
|
116 | |||
117 | /** |
||
118 | * Set how many seconds a stale representation can be used while revalidating in the background. |
||
119 | * |
||
120 | * @param int $seconds |
||
121 | * @return static |
||
122 | */ |
||
123 | 1 | public function withStaleWhileRevalidate($seconds) |
|
127 | |||
128 | /** |
||
129 | * @return int|null |
||
130 | */ |
||
131 | 1 | public function getStaleWhileRevalidate() |
|
135 | |||
136 | /** |
||
137 | * Set how many seconds a stale representation can be used in the case of a server error. |
||
138 | * |
||
139 | * @param int $seconds |
||
140 | * @return static |
||
141 | */ |
||
142 | 1 | public function withStaleIfError($seconds) |
|
146 | |||
147 | /** |
||
148 | * @return int|null |
||
149 | */ |
||
150 | 1 | public function getStaleIfError() |
|
154 | |||
155 | /** |
||
156 | * Set whether a stale representation should be validated. |
||
157 | * |
||
158 | * @param bool $flag |
||
159 | * @return static |
||
160 | */ |
||
161 | 1 | public function withMustRevalidate($flag = true) |
|
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | 1 | public function hasMustRevalidate() |
|
173 | |||
174 | /** |
||
175 | * Set whether a public cache should validate a stale representation. |
||
176 | * |
||
177 | * @param bool $flag |
||
178 | * @return static |
||
179 | */ |
||
180 | 1 | public function withProxyRevalidate($flag = true) |
|
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | 1 | public function hasProxyRevalidate() |
|
192 | |||
193 | /** |
||
194 | * Convenience method to set flags which should prevent the client from caching. |
||
195 | * Adds `no-cache, no-store, must-revalidate`. |
||
196 | * |
||
197 | * @return static |
||
198 | */ |
||
199 | 1 | public function withCachePrevention() |
|
203 | |||
204 | /** |
||
205 | * Sets the flag for the public and private directives. |
||
206 | * |
||
207 | * @param bool $isPublic |
||
208 | * @param bool $flag |
||
209 | * @return static |
||
210 | */ |
||
211 | 5 | private function withPublicPrivate($isPublic, $flag) |
|
223 | } |
||
224 |