JsonSerializer::active()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
/**
6
 * Serializer for json.
7
 * @author Christian Blank <[email protected]>
8
 */
9
class JsonSerializer extends \SS_Object implements IRestSerializer {
10
11
    /**
12
     * @config
13
     */
14
    private static $is_active = true;
15
16
    /**
17
     * The content type.
18
     * @var string
19
     */
20
    private $contentType = "application/json";
21
22
    /**
23
     * Serializes the given data into a json string.
24
     *
25
     * @param array $data the data that should be serialized
26
     * @return string a json formatted string
27
     */
28
    public function serialize($data) {
29
        return json_encode($data, JSON_PRETTY_PRINT);
30
    }
31
32
    public function contentType() {
33
        return $this->contentType;
34
    }
35
36
    /**
37
     * Indicates if the serializer is active.
38
     * Serializers can be deactivated to use another implementation for the same mime type.
39
     *
40
     * @return boolean
41
     */
42
    public function active() {
43
        return $this->config()->get('is_active');
44
    }
45
}
46