55
66class JsonResponse extends \Symfony \Component \HttpFoundation \JsonResponse {
77
8+ /**
9+ * The json encoding options.
10+ *
11+ * @var int
12+ */
13+ protected $ jsonOptions ;
14+
15+ /**
16+ * Constructor.
17+ *
18+ * @param mixed $data
19+ * @param int $status
20+ * @param array $headers
21+ * @param int $options
22+ */
23+ public function __construct ($ data = null , $ status = 200 , $ headers = array (), $ options = 0 )
24+ {
25+ $ this ->jsonOptions = $ options ;
26+
27+ parent ::__construct ($ data , $ status , $ headers );
28+ }
29+
830 /**
931 * Get the json_decoded data from the response
1032 *
@@ -13,8 +35,11 @@ class JsonResponse extends \Symfony\Component\HttpFoundation\JsonResponse {
1335 * @param int $options
1436 * @return mixed
1537 */
16- public function getData ($ assoc = false , $ depth = 512 , $ options = 0 )
38+ public function getData ($ assoc = false , $ depth = 512 , $ options = null )
1739 {
40+ if (is_null ($ options ))
41+ $ options = $ this ->jsonOptions ;
42+
1843 return json_decode ($ this ->data , $ assoc , $ depth , $ options );
1944 }
2045
@@ -23,7 +48,7 @@ public function getData($assoc = false, $depth = 512, $options = 0)
2348 */
2449 public function setData ($ data = array ())
2550 {
26- $ this ->data = $ data instanceof JsonableInterface ? $ data ->toJson () : json_encode ($ data );
51+ $ this ->data = $ data instanceof JsonableInterface ? $ data ->toJson ($ this -> jsonOptions ) : json_encode ($ data, $ this -> jsonOptions );
2752
2853 return $ this ->update ();
2954 }
@@ -56,4 +81,4 @@ public function withCookie(Cookie $cookie)
5681 return $ this ;
5782 }
5883
59- }
84+ }
0 commit comments