1 | <?php |
||
13 | class LimitStream implements StreamInterface |
||
14 | { |
||
15 | use StreamDecoratorTrait; |
||
16 | |||
17 | /** |
||
18 | * @var int Offset to start reading from |
||
19 | */ |
||
20 | private $offset; |
||
21 | |||
22 | /** |
||
23 | * @var int Limit the number of bytes that can be read |
||
24 | */ |
||
25 | private $limit; |
||
26 | |||
27 | /** |
||
28 | * @param StreamInterface $stream Stream to wrap |
||
29 | * @param int $limit Total number of bytes to allow to be read |
||
30 | * from the stream. Pass -1 for no limit. |
||
31 | * @param int|null $offset Position to seek to before reading (only |
||
32 | * works on seekable streams). |
||
33 | */ |
||
34 | 17 | public function __construct( |
|
43 | |||
44 | 9 | public function eof() |
|
58 | |||
59 | /** |
||
60 | * Returns the size of the limited subset of data |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 3 | public function getSize() |
|
73 | |||
74 | /** |
||
75 | * Allow for a bounded seek on the read limited stream |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | 6 | public function seek($offset, $whence = SEEK_SET) |
|
98 | |||
99 | /** |
||
100 | * Give a relative tell() |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 3 | public function tell() |
|
107 | |||
108 | /** |
||
109 | * Set the offset to start limiting from |
||
110 | * |
||
111 | * @param int $offset Offset to seek to and begin byte limiting from |
||
112 | * |
||
113 | * @throws \RuntimeException if the stream cannot be seeked. |
||
114 | */ |
||
115 | 17 | public function setOffset($offset) |
|
132 | |||
133 | /** |
||
134 | * Set the limit of bytes that the decorator allows to be read from the |
||
135 | * stream. |
||
136 | * |
||
137 | * @param int $limit Number of bytes to allow to be read from the stream. |
||
138 | * Use -1 for no limit. |
||
139 | */ |
||
140 | 17 | public function setLimit($limit) |
|
144 | |||
145 | 9 | public function read($length) |
|
162 | } |
||
163 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: