-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJsonCompact.php
More file actions
52 lines (41 loc) · 1.35 KB
/
JsonCompact.php
File metadata and controls
52 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace SimPod\ClickHouseClient\Output;
use JsonException;
use function json_decode;
use const JSON_THROW_ON_ERROR;
/**
* @phpstan-immutable
* @template T
* @implements Output<T>
*/
final readonly class JsonCompact implements Output
{
/** @var list<T> */
public array $data;
/** @var array<mixed> */
public array $meta;
public int $rows;
public int|null $rowsBeforeLimitAtLeast;
/** @var array{elapsed: float, rows_read: int, bytes_read: int} */
public array $statistics;
/** @throws JsonException */
public function __construct(string $contentsJson)
{
/**
* @var array{
* data: list<T>,
* meta: array<mixed>,
* rows: int,
* rows_before_limit_at_least?: int,
* statistics: array{elapsed: float, rows_read: int, bytes_read: int}
* } $contents
*/
$contents = json_decode($contentsJson, true, flags: JSON_THROW_ON_ERROR);
$this->data = $contents['data'];
$this->meta = $contents['meta'];
$this->rows = $contents['rows'];
$this->rowsBeforeLimitAtLeast = $contents['rows_before_limit_at_least'] ?? null;
$this->statistics = $contents['statistics'];
}
}