1 | <?php |
||
18 | class JsonFormat implements FormatInterface, JsonFormatInterface |
||
19 | { |
||
20 | use GetOptionTrait; |
||
21 | |||
22 | const OPTION_FILE_TYPE = 'fileType'; |
||
23 | const OPTION_ENCODE_OPTIONS = 'encodeOptions'; |
||
24 | const OPTION_DECODE_OPTIONS = 'decodeOptions'; |
||
25 | const OPTION_DECODE_ASSOC = 'decodeAssoc'; |
||
26 | const OPTION_IGNORE_BLANK_LINES = 'ignoreBlankLines'; |
||
27 | |||
28 | const DEFAULT_TYPE = JsonFormatInterface::JSON_FILE_TYPE_SINGLE_BLOCK; |
||
29 | const DEFAULT_ENCODE_OPTIONS = 0; |
||
30 | const DEFAULT_DECODE_OPTIONS = 0; |
||
31 | const DEFAULT_DECODE_ASSOC = false; |
||
32 | const DEFAULT_IGNORE_BLANK_LINES = true; |
||
33 | |||
34 | /** |
||
35 | * The type of the file |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | private $fileType = JsonFormatInterface::JSON_FILE_TYPE_SINGLE_BLOCK; |
||
40 | /** @var int */ |
||
41 | private $encodeOptions = 0; |
||
42 | /** @var int */ |
||
43 | private $decodeOptions = 0; |
||
44 | /** @var bool */ |
||
45 | private $decodeToAssoc = false; |
||
46 | /** @var bool */ |
||
47 | private $ignoreBlankLines; |
||
48 | |||
49 | /** |
||
50 | * @param array $options -fileType <int> (Default: JsonFormat::JSON_FILE_TYPE_SINGLE_BLOCK) a |
||
51 | * JsonFormat::JSON_FILE_TYPE_* |
||
52 | * -encodeOptions <int> Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, |
||
53 | * JSON_HEX_APOS, JSON_PRETTY_PRINT, JSON_NUMERIC_CHECK, JSON_UNESCAPED_SLASHES, |
||
54 | * JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, |
||
55 | * JSON_PARTIAL_OUTPUT_ON_ERROR. The behaviour of these constants is described on the JSON |
||
56 | * constants page. |
||
57 | * -decodeOptions <int> Bitmask of JSON decode options. Currently only |
||
58 | * JSON_BIGINT_AS_STRING |
||
59 | * is supported (default is to cast large integers as floats) |
||
60 | */ |
||
61 | 7 | public function __construct(array $options = []) |
|
73 | |||
74 | /** |
||
75 | * Type type of file format |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 3 | public function getType() |
|
83 | |||
84 | /** |
||
85 | * Each line is an individual json blob |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | 13 | public function isEachLine() |
|
93 | |||
94 | /** |
||
95 | * The whole file is a single json blob |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | 6 | public function isSingleBlock() |
|
103 | |||
104 | /** |
||
105 | * @param int $fileType |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 1 | public function setJsonFileType($fileType) |
|
114 | |||
115 | /** |
||
116 | * Get the type of json file ::JSON_FILE_TYPE_* |
||
117 | * |
||
118 | * @return int static::JSON_FILE_TYPE_* |
||
119 | */ |
||
120 | 3 | public function getJsonFileType() |
|
124 | |||
125 | /** |
||
126 | * Set the encoding options. |
||
127 | * |
||
128 | * @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, |
||
129 | * JSON_PRETTY_PRINT, JSON_NUMERIC_CHECK, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, |
||
130 | * JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR. The |
||
131 | * behaviour of these constants is described on the JSON constants page. |
||
132 | * |
||
133 | * @link http://php.net/manual/en/json.constants.php |
||
134 | * |
||
135 | * @return $this |
||
136 | */ |
||
137 | 1 | public function setJsonEncodeOptions($options) |
|
142 | |||
143 | /** |
||
144 | * Get the Json Encode Options |
||
145 | * |
||
146 | * Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, |
||
147 | * JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, |
||
148 | * JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR. |
||
149 | * |
||
150 | * The behaviour of these constants is described on the JSON constants page. |
||
151 | * |
||
152 | * @link http://php.net/manual/en/json.constants.php |
||
153 | * |
||
154 | * @return int |
||
155 | */ |
||
156 | 9 | public function getJsonEncodeOptions() |
|
160 | |||
161 | /** |
||
162 | * @param int $options Bitmask of JSON decode options. Currently only |
||
163 | * JSON_BIGINT_AS_STRING |
||
164 | * is supported (default is to cast large integers as floats) |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | 1 | public function setJsonDecodeOptions($options) |
|
173 | |||
174 | /** |
||
175 | * Bitmask of JSON decode options. Currently only |
||
176 | * JSON_BIGINT_AS_STRING |
||
177 | * is supported (default is to cast large integers as floats) |
||
178 | * |
||
179 | * @return mixed |
||
180 | */ |
||
181 | 9 | public function getJsonDecodeOptions() |
|
185 | |||
186 | /** |
||
187 | * @param bool $assoc |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | 1 | public function setJsonDecodeAssoc($assoc) |
|
196 | |||
197 | /** |
||
198 | * @return bool |
||
199 | */ |
||
200 | 9 | public function isJsonDecodeAssoc() |
|
204 | |||
205 | /** |
||
206 | * @param bool $ignore |
||
207 | * |
||
208 | * @return $this |
||
209 | */ |
||
210 | 1 | public function setIgnoreBlankLines($ignore) |
|
215 | |||
216 | /** |
||
217 | * @return bool |
||
218 | */ |
||
219 | 7 | public function isIgnoreBlankLines() |
|
223 | } |
||
224 |