18
18
*/
19
19
class JsonDecode implements DecoderInterface
20
20
{
21
+ /**
22
+ * Specifies if the returned result should be an associative array or a nested stdClass object hierarchy
23
+ * @var bool
24
+ */
21
25
private $ associative ;
26
+
27
+ /**
28
+ * Specifies the recursion depth
29
+ * @var int
30
+ */
22
31
private $ recursionDepth ;
32
+
23
33
private $ lastError = JSON_ERROR_NONE ;
24
34
protected $ serializer ;
25
35
36
+ /**
37
+ * Constructs a new JsonDecode instance.
38
+ *
39
+ * @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy.
40
+ * @param int $depth Specifies the recursion depth
41
+ */
26
42
public function __construct ($ associative = false , $ depth = 512 )
27
43
{
28
44
$ this ->associative = $ associative ;
29
- $ this ->recursionDepth = $ depth ;
45
+ $ this ->recursionDepth = ( int ) $ depth ;
30
46
}
31
47
32
48
/**
@@ -42,12 +58,27 @@ public function getLastError()
42
58
}
43
59
44
60
/**
45
- * Decodes a JSON string into PHP data
61
+ * @param string $data The encoded JSON string to decode
62
+ * @param string $format Must be set to JsonEncoder::FORMAT
63
+ * @param array $context An optional set of options for the JSON decoder; see below.
64
+ *
65
+ * The $context array is a simple key=>value array, with the following supported keys:
46
66
*
47
- * @param string $data JSON
48
- * @param string $format
67
+ * json_decode_associative: boolean
68
+ * If true, returns the object as associative array.
69
+ * If false, returns the object as nested StdClass
70
+ * If not specified, this method will use the default set in JsonDecode::__construct
71
+ *
72
+ * json_decode_recursion_depth: integer
73
+ * Specifies the maximum recursion depth
74
+ * If not specified, this method will use the default set in JsonDecode::__construct
75
+ *
76
+ * json_decode_options: integer
77
+ * Specifies additional options as per documentation for json_decode. Only supported with PHP 5.4.0 and higher.
49
78
*
50
79
* @return mixed
80
+ *
81
+ * @see http://php.net/json_decode json_decode
51
82
*/
52
83
public function decode ($ data , $ format , array $ context = array ())
53
84
{
0 commit comments