1 | <?php |
||
25 | class Stream implements StreamInterface |
||
26 | { |
||
27 | /** @var resource Underlying socket */ |
||
28 | private $socket; |
||
29 | |||
30 | /** |
||
31 | * @var bool Is stream detached |
||
32 | */ |
||
33 | private $isDetached = false; |
||
34 | |||
35 | /** |
||
36 | * @var int|null Size of the stream, so we know what we must read, null if not available (i.e. a chunked stream) |
||
37 | */ |
||
38 | private $size; |
||
39 | |||
40 | /** |
||
41 | * @var int Size of the stream readed, to avoid reading more than available and have the user blocked |
||
42 | */ |
||
43 | private $readed = 0; |
||
44 | |||
45 | /** |
||
46 | * Create the stream. |
||
47 | * |
||
48 | * @param resource $socket |
||
49 | * @param int $size |
||
50 | */ |
||
51 | 71 | public function __construct($socket, $size = null) |
|
52 | { |
||
53 | 71 | $this->socket = $socket; |
|
54 | 71 | $this->size = $size; |
|
55 | 71 | } |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 1 | public function __toString() |
|
68 | |||
69 | /** |
||
70 | * Close the socket when the object is destructed. |
||
71 | */ |
||
72 | 71 | public function __destruct() |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 70 | public function close() |
|
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | 1 | public function detach() |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 58 | public function getSize() |
|
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | 1 | public function tell() |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 1 | public function eof() |
|
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | 1 | public function isSeekable() |
|
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | 1 | public function seek($offset, $whence = SEEK_SET) |
|
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | 1 | public function rewind() |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 1 | public function isWritable() |
|
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | 1 | public function write($string) |
|
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | 1 | public function isReadable() |
|
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | 5 | public function read($length) |
|
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | 57 | public function getContents() |
|
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | 6 | public function getMetadata($key = null) |
|
227 | } |
||
228 |