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 | 5 | public function __destruct() |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 1 | public function close() |
|
84 | 1 | ||
85 | /** |
||
86 | 1 | * {@inheritdoc} |
|
87 | */ |
||
88 | public function detach() |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 1 | public function getSize() |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 1 | public function tell() |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 1 | public function eof() |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 1 | public function isSeekable() |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 1 | public function seek($offset, $whence = SEEK_SET) |
|
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | 1 | public function rewind() |
|
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | 1 | public function isWritable() |
|
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | 1 | public function write($string) |
|
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | 5 | public function isReadable() |
|
168 | |||
169 | /** |
||
170 | 5 | * {@inheritdoc} |
|
171 | 1 | */ |
|
172 | public function read($length) |
||
193 | |||
194 | /** |
||
195 | 4 | * {@inheritdoc} |
|
196 | */ |
||
197 | public function getContents() |
||
211 | 6 | ||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | 6 | public function getMetadata($key = null) |
|
225 | } |
||
226 |