| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | protected function formatResponse(array $data) |
||
| 11 | { |
||
| 12 | $response = new SS_HTTPResponse(); |
||
| 13 | $response |
||
| 14 | ->addHeader('Content-Type', 'application/json') |
||
| 15 | ->setBody(Convert::raw2json($data, JSON_PRETTY_PRINT)); |
||
| 16 | |||
| 17 | // Don't cache anything in dev mode |
||
| 18 | if (Director::get_environment_type() !== 'dev') { |
||
| 19 | // Only cache failure messages for one minute, otherwise use the configured cache age |
||
| 20 | $cacheAge = empty($data['success']) ? 60 : Config::inst()->get(__CLASS__, 'cache_age'); |
||
| 21 | $response->addHeader('Cache-Control', 'max-age=' . $cacheAge); |
||
| 22 | } |
||
| 23 | |||
| 24 | return $response; |
||
| 25 | } |
||
| 26 | } |
||
| 27 |