1 | <?php |
||
38 | class JsonResponseFormatter extends Component implements ResponseFormatterInterface |
||
39 | { |
||
40 | /** |
||
41 | * @var boolean whether to use JSONP response format. When this is true, the [[Response::data|response data]] |
||
42 | * must be an array consisting of `data` and `callback` members. The latter should be a JavaScript |
||
43 | * function name while the former will be passed to this function as a parameter. |
||
44 | */ |
||
45 | public $useJsonp = false; |
||
46 | /** |
||
47 | * @var integer the encoding options passed to [[Json::encode()]]. For more details please refer to |
||
48 | * <http://www.php.net/manual/en/function.json-encode.php>. |
||
49 | * Default is `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE`. |
||
50 | * This property has no effect, when [[useJsonp]] is `true`. |
||
51 | * @since 2.0.7 |
||
52 | */ |
||
53 | public $encodeOptions = 320; |
||
54 | /** |
||
55 | * @var bool whether to format the output in a readable "pretty" format. This can be useful for debugging purpose. |
||
56 | * If this is true, `JSON_PRETTY_PRINT` will be added to [[encodeOptions]]. |
||
57 | * Defaults to `false`. |
||
58 | * This property has no effect, when [[useJsonp]] is `true`. |
||
59 | * @since 2.0.7 |
||
60 | */ |
||
61 | public $prettyPrint = false; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Formats the specified response. |
||
66 | * @param Response $response the response to be formatted. |
||
67 | */ |
||
68 | 19 | public function format($response) |
|
76 | |||
77 | /** |
||
78 | * Formats response data in JSON format. |
||
79 | * @param Response $response |
||
80 | */ |
||
81 | 19 | protected function formatJson($response) |
|
92 | |||
93 | /** |
||
94 | * Formats response data in JSONP format. |
||
95 | * @param Response $response |
||
96 | */ |
||
97 | protected function formatJsonp($response) |
||
107 | } |
||
108 |