1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace ClickHouseDB; |
4
|
|
|
|
5
|
|
|
use ClickHouseDB\Exception\ClickHouseUnavailableException; |
6
|
|
|
use ClickHouseDB\Exception\DatabaseException; |
7
|
|
|
use ClickHouseDB\Exception\QueryException; |
8
|
|
|
use ClickHouseDB\Query\Query; |
9
|
|
|
use ClickHouseDB\Transport\CurlerRequest; |
10
|
|
|
use ClickHouseDB\Transport\CurlerResponse; |
11
|
|
|
|
12
|
|
|
class Statement |
13
|
|
|
{ |
14
|
|
|
/** |
|
|
|
|
15
|
|
|
* @var string|mixed |
16
|
|
|
*/ |
17
|
|
|
private $_rawData; |
18
|
|
|
|
19
|
|
|
/** |
|
|
|
|
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
private $_http_code = -1; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
|
|
|
|
25
|
|
|
* @var CurlerRequest |
26
|
|
|
*/ |
27
|
|
|
private $_request = null; |
28
|
|
|
|
29
|
|
|
/** |
|
|
|
|
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private $_init = false; |
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* @var Query |
36
|
|
|
*/ |
37
|
|
|
private $query; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* @var mixed |
41
|
|
|
*/ |
42
|
|
|
private $format; |
43
|
|
|
|
44
|
|
|
/** |
|
|
|
|
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $sql = ''; |
48
|
|
|
|
49
|
|
|
/** |
|
|
|
|
50
|
|
|
* @var array |
|
|
|
|
51
|
|
|
*/ |
52
|
|
|
private $meta; |
53
|
|
|
|
54
|
|
|
/** |
|
|
|
|
55
|
|
|
* @var array |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
private $totals; |
58
|
|
|
|
59
|
|
|
/** |
|
|
|
|
60
|
|
|
* @var array |
|
|
|
|
61
|
|
|
*/ |
62
|
|
|
private $extremes; |
63
|
|
|
|
64
|
|
|
/** |
|
|
|
|
65
|
|
|
* @var int |
66
|
|
|
*/ |
67
|
|
|
private $rows; |
68
|
|
|
|
69
|
|
|
/** |
|
|
|
|
70
|
|
|
* @var bool|integer |
|
|
|
|
71
|
|
|
*/ |
72
|
|
|
private $rows_before_limit_at_least = false; |
73
|
|
|
|
74
|
|
|
/** |
|
|
|
|
75
|
|
|
* @var array |
|
|
|
|
76
|
|
|
*/ |
77
|
|
|
private $array_data = []; |
78
|
|
|
|
79
|
|
|
/** |
|
|
|
|
80
|
|
|
* @var array|null |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
private $statistics = null; |
83
|
|
|
|
84
|
|
|
/** |
|
|
|
|
85
|
|
|
* @var int |
86
|
|
|
*/ |
87
|
|
|
public $iterator=0; |
|
|
|
|
88
|
|
|
|
89
|
|
|
|
90
|
44 |
|
public function __construct(CurlerRequest $request) |
|
|
|
|
91
|
|
|
{ |
92
|
44 |
|
$this->_request = $request; |
93
|
44 |
|
$this->format = $this->_request->getRequestExtendedInfo('format'); |
|
|
|
|
94
|
44 |
|
$this->query = $this->_request->getRequestExtendedInfo('query'); |
|
|
|
|
95
|
44 |
|
$this->sql = $this->_request->getRequestExtendedInfo('sql'); |
|
|
|
|
96
|
44 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return CurlerRequest |
100
|
|
|
*/ |
101
|
|
|
public function getRequest() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
return $this->_request; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return CurlerResponse |
|
|
|
|
108
|
|
|
* @throws Exception\TransportException |
|
|
|
|
109
|
|
|
*/ |
110
|
38 |
|
private function response() |
|
|
|
|
111
|
|
|
{ |
112
|
38 |
|
return $this->_request->response(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return mixed |
|
|
|
|
117
|
|
|
* @throws Exception\TransportException |
|
|
|
|
118
|
|
|
*/ |
119
|
1 |
|
public function responseInfo() |
120
|
|
|
{ |
121
|
1 |
|
return $this->response()->info(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return mixed|string |
126
|
|
|
*/ |
127
|
11 |
|
public function sql() |
128
|
|
|
{ |
129
|
11 |
|
return $this->sql; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $body |
|
|
|
|
134
|
|
|
* @return array|bool |
|
|
|
|
135
|
|
|
*/ |
136
|
5 |
|
private function parseErrorClickHouse($body) |
|
|
|
|
137
|
|
|
{ |
138
|
5 |
|
$body = trim($body); |
|
|
|
|
139
|
5 |
|
$mathes = []; |
140
|
|
|
|
141
|
|
|
// Code: 115, e.displayText() = DB::Exception: Unknown setting readonly[0], e.what() = DB::Exception |
142
|
|
|
// Code: 192, e.displayText() = DB::Exception: Unknown user x, e.what() = DB::Exception |
143
|
|
|
// Code: 60, e.displayText() = DB::Exception: Table default.ZZZZZ doesn't exist., e.what() = DB::Exception |
144
|
|
|
|
145
|
5 |
|
if (preg_match("%Code: (\d+),\se\.displayText\(\) \=\s*DB\:\:Exception\s*:\s*(.*)(?:\,\s*e\.what|\(version).*%ius", $body, $mathes)) { |
|
|
|
|
146
|
5 |
|
return ['code' => $mathes[1], 'message' => $mathes[2]]; |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return false; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
|
|
|
|
154
|
|
|
* @throws Exception\TransportException |
|
|
|
|
155
|
|
|
*/ |
156
|
8 |
|
public function error() |
|
|
|
|
157
|
|
|
{ |
158
|
8 |
|
if (!$this->isError()) { |
|
|
|
|
159
|
2 |
|
return false; |
160
|
|
|
} |
161
|
|
|
|
162
|
6 |
|
$body = $this->response()->body(); |
|
|
|
|
163
|
6 |
|
$error_no = $this->response()->error_no(); |
164
|
6 |
|
$error = $this->response()->error(); |
|
|
|
|
165
|
|
|
|
166
|
6 |
|
$dumpStatement = false; |
167
|
6 |
|
if (!$error_no && !$error) { |
|
|
|
|
168
|
5 |
|
$parse = $this->parseErrorClickHouse($body); |
169
|
|
|
|
170
|
5 |
|
if ($parse) { |
|
|
|
|
171
|
5 |
|
throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']); |
172
|
|
|
} else { |
173
|
|
|
$code = $this->response()->http_code(); |
|
|
|
|
174
|
|
|
$message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body; |
|
|
|
|
175
|
|
|
$dumpStatement = true; |
176
|
|
|
} |
177
|
|
|
} else { |
178
|
1 |
|
$code = $error_no; |
|
|
|
|
179
|
1 |
|
$message = $this->response()->error(); |
180
|
|
|
} |
181
|
|
|
|
182
|
1 |
|
$exception = new QueryException($message, $code); |
183
|
1 |
|
if ($code === CURLE_COULDNT_CONNECT) { |
|
|
|
|
184
|
|
|
$exception = new ClickHouseUnavailableException($message, $code); |
185
|
|
|
} |
186
|
|
|
|
187
|
1 |
|
if ($dumpStatement) { |
|
|
|
|
188
|
|
|
$exception->setRequestDetails($this->_request->getDetails()); |
189
|
|
|
$exception->setResponseDetails($this->response()->getDetails()); |
190
|
|
|
} |
191
|
|
|
|
192
|
1 |
|
throw $exception; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return bool |
|
|
|
|
197
|
|
|
* @throws Exception\TransportException |
|
|
|
|
198
|
|
|
*/ |
199
|
38 |
|
public function isError() |
|
|
|
|
200
|
|
|
{ |
201
|
38 |
|
return ($this->response()->http_code() !== 200 || $this->response()->error_no()); |
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
31 |
|
private function check() : bool |
|
|
|
|
205
|
|
|
{ |
206
|
31 |
|
if (!$this->_request->isResponseExists()) { |
|
|
|
|
207
|
|
|
throw QueryException::noResponse(); |
208
|
|
|
} |
209
|
|
|
|
210
|
31 |
|
if ($this->isError()) { |
211
|
1 |
|
$this->error(); |
212
|
|
|
} |
213
|
|
|
|
214
|
30 |
|
return true; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return bool |
|
|
|
|
219
|
|
|
* @throws Exception\TransportException |
|
|
|
|
220
|
|
|
*/ |
221
|
29 |
|
private function init() |
|
|
|
|
222
|
|
|
{ |
223
|
29 |
|
if ($this->_init) { |
224
|
|
|
return false; |
225
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
228
|
29 |
|
$this->check(); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
231
|
28 |
|
$this->_rawData = $this->response()->rawDataOrJson($this->format); |
232
|
|
|
|
233
|
28 |
|
if (!$this->_rawData) { |
|
|
|
|
234
|
|
|
$this->_init = true; |
235
|
|
|
return false; |
236
|
|
|
} |
|
|
|
|
237
|
28 |
|
$data=[]; |
|
|
|
|
238
|
28 |
|
foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least', 'statistics'] as $key) { |
|
|
|
|
239
|
|
|
|
240
|
28 |
|
if (isset($this->_rawData[$key])) { |
|
|
|
|
241
|
28 |
|
if ($key=='data') |
|
|
|
|
242
|
|
|
{ |
243
|
28 |
|
$data=$this->_rawData[$key]; |
|
|
|
|
244
|
|
|
} |
245
|
|
|
else{ |
|
|
|
|
246
|
28 |
|
$this->{$key} = $this->_rawData[$key]; |
247
|
|
|
} |
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
28 |
|
if (empty($this->meta)) { |
253
|
|
|
throw new QueryException('Can`t find meta'); |
254
|
|
|
} |
255
|
|
|
|
256
|
28 |
|
$isJSONCompact=(stripos($this->format,'JSONCompact')!==false?true:false); |
|
|
|
|
257
|
28 |
|
$this->array_data = []; |
258
|
28 |
|
foreach ($data as $rows) { |
259
|
28 |
|
$r = []; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
262
|
28 |
|
if ($isJSONCompact) |
263
|
|
|
{ |
264
|
1 |
|
$r[]=$rows; |
|
|
|
|
265
|
|
|
} |
266
|
|
|
else { |
267
|
27 |
|
foreach ($this->meta as $meta) { |
268
|
27 |
|
$r[$meta['name']] = $rows[$meta['name']]; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
28 |
|
$this->array_data[] = $r; |
273
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
276
|
28 |
|
return true; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return array |
|
|
|
|
281
|
|
|
* @throws \Exception |
|
|
|
|
282
|
|
|
*/ |
283
|
|
|
public function extremes() |
|
|
|
|
284
|
|
|
{ |
285
|
|
|
$this->init(); |
286
|
|
|
return $this->extremes; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @return mixed |
|
|
|
|
291
|
|
|
* @throws Exception\TransportException |
|
|
|
|
292
|
|
|
*/ |
293
|
1 |
|
public function totalTimeRequest() |
294
|
|
|
{ |
295
|
1 |
|
$this->check(); |
296
|
1 |
|
return $this->response()->total_time(); |
297
|
|
|
|
298
|
|
|
} |
|
|
|
|
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @return array |
|
|
|
|
302
|
|
|
* @throws \Exception |
|
|
|
|
303
|
|
|
*/ |
304
|
1 |
|
public function extremesMin() |
|
|
|
|
305
|
|
|
{ |
306
|
1 |
|
$this->init(); |
307
|
|
|
|
308
|
1 |
|
if (empty($this->extremes['min'])) { |
309
|
|
|
return []; |
310
|
|
|
} |
311
|
|
|
|
312
|
1 |
|
return $this->extremes['min']; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return array |
|
|
|
|
317
|
|
|
* @throws \Exception |
|
|
|
|
318
|
|
|
*/ |
319
|
|
|
public function extremesMax() |
|
|
|
|
320
|
|
|
{ |
321
|
|
|
$this->init(); |
322
|
|
|
|
323
|
|
|
if (empty($this->extremes['max'])) { |
324
|
|
|
return []; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
return $this->extremes['max']; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return array |
|
|
|
|
332
|
|
|
* @throws Exception\TransportException |
|
|
|
|
333
|
|
|
*/ |
334
|
1 |
|
public function totals() |
|
|
|
|
335
|
|
|
{ |
336
|
1 |
|
$this->init(); |
337
|
1 |
|
return $this->totals; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
|
|
|
|
341
|
|
|
* |
342
|
|
|
*/ |
|
|
|
|
343
|
|
|
public function dumpRaw() |
|
|
|
|
344
|
|
|
{ |
345
|
|
|
print_r($this->_rawData); |
|
|
|
|
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
|
|
|
|
349
|
|
|
* |
350
|
|
|
*/ |
|
|
|
|
351
|
|
|
public function dump() |
|
|
|
|
352
|
|
|
{ |
353
|
|
|
$this->_request->dump(); |
354
|
|
|
$this->response()->dump(); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @return bool|int |
|
|
|
|
359
|
|
|
* @throws Exception\TransportException |
|
|
|
|
360
|
|
|
*/ |
361
|
2 |
|
public function countAll() |
362
|
|
|
{ |
363
|
2 |
|
$this->init(); |
364
|
2 |
|
return $this->rows_before_limit_at_least; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param bool $key |
|
|
|
|
369
|
|
|
* @return array|mixed|null |
|
|
|
|
370
|
|
|
* @throws Exception\TransportException |
|
|
|
|
371
|
|
|
*/ |
372
|
|
|
public function statistics($key = false) |
|
|
|
|
373
|
|
|
{ |
374
|
|
|
$this->init(); |
375
|
|
|
|
376
|
|
|
if (!is_array($this->statistics)) { |
|
|
|
|
377
|
|
|
return null; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
if (!$key) return $this->statistics; |
|
|
|
|
381
|
|
|
|
382
|
|
|
if (!isset($this->statistics[$key])) { |
383
|
|
|
return null; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
return $this->statistics[$key]; |
387
|
|
|
|
388
|
|
|
} |
|
|
|
|
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @return int |
392
|
|
|
* @throws Exception\TransportException |
393
|
|
|
*/ |
394
|
8 |
|
public function count() |
395
|
|
|
{ |
396
|
8 |
|
$this->init(); |
397
|
8 |
|
return $this->rows; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @return mixed|string |
402
|
|
|
* @throws Exception\TransportException |
403
|
|
|
*/ |
404
|
3 |
|
public function rawData() |
405
|
|
|
{ |
406
|
3 |
|
if ($this->_init) { |
407
|
|
|
return $this->_rawData; |
408
|
|
|
} |
409
|
|
|
|
410
|
3 |
|
$this->check(); |
411
|
|
|
|
412
|
3 |
|
return $this->response()->rawDataOrJson($this->format); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* |
417
|
|
|
*/ |
418
|
2 |
|
public function resetIterator() |
419
|
|
|
{ |
420
|
2 |
|
$this->iterator=0; |
421
|
2 |
|
} |
422
|
|
|
|
423
|
2 |
|
public function fetchRow($key = null) |
424
|
|
|
{ |
425
|
2 |
|
$this->init(); |
426
|
|
|
|
427
|
2 |
|
$position=$this->iterator; |
428
|
|
|
|
429
|
2 |
|
if (!isset($this->array_data[$position])) { |
430
|
|
|
return null; |
431
|
|
|
} |
432
|
|
|
|
433
|
2 |
|
$this->iterator++; |
434
|
|
|
|
435
|
2 |
|
if (!$key) { |
436
|
|
|
return $this->array_data[$position]; |
437
|
|
|
} |
438
|
2 |
|
if (!isset($this->array_data[$position][$key])) { |
439
|
1 |
|
return null; |
440
|
|
|
} |
441
|
|
|
|
442
|
2 |
|
return $this->array_data[$position][$key]; |
443
|
|
|
|
444
|
|
|
} |
445
|
|
|
/** |
446
|
|
|
* @param string $key |
447
|
|
|
* @return mixed|null |
448
|
|
|
* @throws Exception\TransportException |
449
|
|
|
*/ |
450
|
18 |
|
public function fetchOne($key = null) |
451
|
|
|
{ |
452
|
18 |
|
$this->init(); |
453
|
18 |
|
if (!isset($this->array_data[0])) { |
454
|
|
|
return null; |
455
|
|
|
} |
456
|
|
|
|
457
|
18 |
|
if (!$key) { |
458
|
3 |
|
return $this->array_data[0]; |
459
|
|
|
} |
460
|
|
|
|
461
|
18 |
|
if (!isset($this->array_data[0][$key])) { |
462
|
2 |
|
return null; |
463
|
|
|
} |
464
|
|
|
|
465
|
17 |
|
return $this->array_data[0][$key]; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* @param string|null $path |
470
|
|
|
* @return array |
471
|
|
|
* @throws Exception\TransportException |
472
|
|
|
*/ |
473
|
3 |
|
public function rowsAsTree($path) |
474
|
|
|
{ |
475
|
3 |
|
$this->init(); |
476
|
|
|
|
477
|
3 |
|
$out = []; |
478
|
3 |
|
foreach ($this->array_data as $row) { |
479
|
3 |
|
$d = $this->array_to_tree($row, $path); |
480
|
3 |
|
$out = array_replace_recursive($d, $out); |
|
|
|
|
481
|
|
|
} |
482
|
|
|
|
483
|
3 |
|
return $out; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Return size_upload,upload_content,speed_upload,time_request |
488
|
|
|
* |
489
|
|
|
* @return array |
490
|
|
|
* @throws Exception\TransportException |
491
|
|
|
*/ |
492
|
|
|
public function info_upload() |
493
|
|
|
{ |
494
|
|
|
$this->check(); |
495
|
|
|
return [ |
496
|
|
|
'size_upload' => $this->response()->size_upload(), |
497
|
|
|
'upload_content' => $this->response()->upload_content_length(), |
498
|
|
|
'speed_upload' => $this->response()->speed_upload(), |
499
|
|
|
'time_request' => $this->response()->total_time() |
500
|
|
|
]; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Return size_upload,upload_content,speed_upload,time_request,starttransfer_time,size_download,speed_download |
505
|
|
|
* |
506
|
|
|
* @return array |
507
|
|
|
* @throws Exception\TransportException |
508
|
|
|
*/ |
509
|
1 |
|
public function info() |
510
|
|
|
{ |
511
|
1 |
|
$this->check(); |
512
|
|
|
return [ |
513
|
1 |
|
'starttransfer_time' => $this->response()->starttransfer_time(), |
514
|
1 |
|
'size_download' => $this->response()->size_download(), |
515
|
1 |
|
'speed_download' => $this->response()->speed_download(), |
516
|
1 |
|
'size_upload' => $this->response()->size_upload(), |
517
|
1 |
|
'upload_content' => $this->response()->upload_content_length(), |
518
|
1 |
|
'speed_upload' => $this->response()->speed_upload(), |
519
|
1 |
|
'time_request' => $this->response()->total_time() |
520
|
|
|
]; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* get format in sql |
525
|
|
|
* @return mixed |
526
|
|
|
*/ |
527
|
1 |
|
public function getFormat() |
528
|
|
|
{ |
529
|
1 |
|
return $this->format; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @return array |
534
|
|
|
* @throws Exception\TransportException |
535
|
|
|
*/ |
536
|
9 |
|
public function rows() |
537
|
|
|
{ |
538
|
9 |
|
$this->init(); |
539
|
8 |
|
return $this->array_data; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @param array|string $arr |
544
|
|
|
* @param null|string|array $path |
545
|
|
|
* @return array |
546
|
|
|
*/ |
547
|
3 |
|
private function array_to_tree($arr, $path = null) |
548
|
|
|
{ |
549
|
3 |
|
if (is_array($path)) { |
|
|
|
|
550
|
|
|
$keys = $path; |
551
|
|
|
} else { |
552
|
3 |
|
$args = func_get_args(); |
|
|
|
|
553
|
3 |
|
array_shift($args); |
|
|
|
|
554
|
|
|
|
555
|
3 |
|
if (sizeof($args) < 2) { |
|
|
|
|
556
|
3 |
|
$separator = '.'; |
557
|
3 |
|
$keys = explode($separator, $path); |
|
|
|
|
558
|
|
|
} else { |
559
|
|
|
$keys = $args; |
560
|
|
|
} |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
// |
564
|
3 |
|
$tree = $arr; |
565
|
3 |
|
while (count($keys)) { |
|
|
|
|
566
|
3 |
|
$key = array_pop($keys); |
|
|
|
|
567
|
|
|
|
568
|
3 |
|
if (isset($arr[$key])) { |
569
|
3 |
|
$val = $arr[$key]; |
570
|
|
|
} else { |
571
|
|
|
$val = $key; |
572
|
|
|
} |
573
|
|
|
|
574
|
3 |
|
$tree = array($val => $tree); |
575
|
|
|
} |
576
|
3 |
|
if (!is_array($tree)) { |
|
|
|
|
577
|
|
|
return []; |
578
|
|
|
} |
579
|
3 |
|
return $tree; |
580
|
|
|
} |
581
|
|
|
} |
582
|
|
|
|