aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/restapi/renderer/JSONRenderer.php
blob: 9c6e449e5e603dbeef29bf4fc02281cd56817c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace RESTAPI\Renderer;

/**
 * Content renderer for json content.
 *
 * @author     Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @author     <mlunzena@uos.de>
 * @license    GPL 2 or later
 * @since      Stud.IP 3.0
 * @deprecated Since Stud.IP 5.0. Will be removed in Stud.IP 6.0.
 */
class JSONRenderer extends DefaultRenderer
{
    public function contentType()
    {
        return 'application/json';
    }

    public function extension()
    {
        return '.json';
    }

    public function render($response)
    {
        if (!isset($response['Content-Type'])) {
            $response['Content-Type'] = $this->contentType() . ';charset=utf-8';
        }

        if (isset($response->body)) {
            $response->body = json_encode($response->body);
        }
    }
}