-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJsonEachRow.php
More file actions
36 lines (29 loc) · 723 Bytes
/
JsonEachRow.php
File metadata and controls
36 lines (29 loc) · 723 Bytes
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
<?php
declare(strict_types=1);
namespace SimPod\ClickHouseClient\Output;
use JsonException;
use function json_decode;
use function sprintf;
use function str_replace;
use const JSON_THROW_ON_ERROR;
/**
* @phpstan-immutable
* @template T
* @implements Output<T>
*/
final readonly class JsonEachRow implements Output
{
/** @var list<T> */
public array $data;
/** @throws JsonException */
public function __construct(string $contentsJson)
{
/** @var list<T> $contents */
$contents = json_decode(
sprintf('[%s]', str_replace("}\n{", '},{', $contentsJson)),
true,
flags: JSON_THROW_ON_ERROR,
);
$this->data = $contents;
}
}