1: <?php
2:
3: namespace Racoon\Api\Response\Format;
4:
5:
6: use Racoon\Api\Exception\ResponseFormattingException;
7:
8: class JsonFormatter implements FormatterInterface
9: {
10:
11: 12: 13: 14: 15:
16: public function format($response)
17: {
18: $formattedResponse = json_encode($response);
19:
20: if ($formattedResponse === false) {
21: throw new ResponseFormattingException(null, 'Could not JSON encode the response.');
22: }
23:
24: return $formattedResponse;
25: }
26:
27:
28: 29: 30:
31: public function getContentType()
32: {
33: return 'application/json';
34: }
35: }