1 | <?php declare(strict_types=1); |
||
8 | class JsonStream implements StreamInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | private $json = []; |
||
14 | |||
15 | /** |
||
16 | * @var StreamInterface |
||
17 | */ |
||
18 | private $bufferStream; |
||
19 | |||
20 | 3 | public function __construct(array $json) |
|
21 | { |
||
22 | 3 | $this->json = $json; |
|
23 | 3 | $jsonString = json_encode($json); |
|
24 | 3 | $this->bufferStream = new BufferStream(strlen($jsonString)); |
|
25 | 3 | $this->bufferStream->write($jsonString); |
|
26 | 3 | } |
|
27 | |||
28 | /** |
||
29 | * @return array |
||
30 | */ |
||
31 | 3 | public function getJson() |
|
32 | { |
||
33 | 3 | return $this->json; |
|
34 | } |
||
35 | |||
36 | public function __toString() |
||
37 | { |
||
38 | return $this->getContents(); |
||
39 | } |
||
40 | |||
41 | 1 | public function getContents() |
|
45 | |||
46 | public function close() |
||
47 | { |
||
48 | } |
||
49 | |||
50 | public function detach() |
||
53 | |||
54 | 1 | public function getSize() |
|
58 | |||
59 | public function isReadable() |
||
63 | |||
64 | public function isWritable() |
||
68 | |||
69 | public function isSeekable() |
||
73 | |||
74 | public function rewind() |
||
78 | |||
79 | public function seek($offset, $whence = SEEK_SET) |
||
83 | |||
84 | public function eof() |
||
88 | |||
89 | public function tell() |
||
93 | |||
94 | /** |
||
95 | * Reads data from the buffer. |
||
96 | */ |
||
97 | public function read($length) |
||
101 | |||
102 | /** |
||
103 | * Writes data to the buffer. |
||
104 | */ |
||
105 | public function write($string) |
||
109 | |||
110 | public function getMetadata($key = null) |
||
114 | } |
||
115 |