17 parent::__construct();
19 $this->jsonEncodingOptions = $options;
29 if (
$data instanceof \JsonSerializable)
31 $this->data = Main\Web\Json::encode(
$data->jsonSerialize(), $this->jsonEncodingOptions);
35 $this->data =
$data->toJson($this->jsonEncodingOptions);
39 $this->data = Main\Web\Json::encode(
$data->toArray(), $this->jsonEncodingOptions);
43 $this->data = Main\Web\Json::encode(
$data, $this->jsonEncodingOptions);
49 private function processData(
$data)
51 if (
$data instanceof \JsonSerializable)
55 elseif (
$data instanceof Contract\Jsonable)
57 $data =
$data->toJson($this->jsonEncodingOptions);
59 elseif (
$data instanceof Contract\Arrayable)
64 if (
$data instanceof DateTime)
66 return date(
'c' ,
$data->getTimestamp());
72 return date(
'c', makeTimeStamp(
$data, FORMAT_DATE) + date(
"Z"));
75 if (
$data instanceof Main\Web\Uri)
77 return $data->getUri();
80 if (
$data instanceof Main\UI\PageNavigation)
83 'currentPage' =>
$data->getCurrentPage(),
84 'pageSize' =>
$data->getPageSize(),
85 'recordCount' =>
$data->getRecordCount(),
89 if (is_array(
$data) ||
$data instanceof \Traversable)
91 foreach (
$data as $key => $item)
93 $data[$key] = $this->processData($item);
102 $this->
addHeader(
'Content-Type',
'application/json; charset=UTF-8');
__construct($data=null, $options=0)
addHeader($name, $value='')