| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 16 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | View Code Duplication | protected function formatResponse(array $data) |
|
| 33 | { |
||
| 34 | $response = new SS_HTTPResponse(); |
||
| 35 | $response |
||
| 36 | ->addHeader('Content-Type', 'application/json') |
||
| 37 | ->setBody(Convert::raw2json($data, JSON_PRETTY_PRINT)); |
||
| 38 | |||
| 39 | // Don't cache anything in dev mode |
||
| 40 | if (Director::get_environment_type() !== 'dev') { |
||
| 41 | // Only cache failure messages for one minute, otherwise use the configured cache age |
||
| 42 | $cacheAge = empty($data['success']) ? 60 : Config::inst()->get(__CLASS__, 'cache_age'); |
||
| 43 | $response->addHeader('Cache-Control', 'max-age=' . $cacheAge); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $response; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |