Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Psr\Http\Message;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Describes a data stream.
|
Chris@0
|
7 *
|
Chris@0
|
8 * Typically, an instance will wrap a PHP stream; this interface provides
|
Chris@0
|
9 * a wrapper around the most common operations, including serialization of
|
Chris@0
|
10 * the entire stream to a string.
|
Chris@0
|
11 */
|
Chris@0
|
12 interface StreamInterface
|
Chris@0
|
13 {
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Reads all data from the stream into a string, from the beginning to end.
|
Chris@0
|
16 *
|
Chris@0
|
17 * This method MUST attempt to seek to the beginning of the stream before
|
Chris@0
|
18 * reading data and read the stream until the end is reached.
|
Chris@0
|
19 *
|
Chris@0
|
20 * Warning: This could attempt to load a large amount of data into memory.
|
Chris@0
|
21 *
|
Chris@0
|
22 * This method MUST NOT raise an exception in order to conform with PHP's
|
Chris@0
|
23 * string casting operations.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
|
Chris@0
|
26 * @return string
|
Chris@0
|
27 */
|
Chris@0
|
28 public function __toString();
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * Closes the stream and any underlying resources.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @return void
|
Chris@0
|
34 */
|
Chris@0
|
35 public function close();
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Separates any underlying resources from the stream.
|
Chris@0
|
39 *
|
Chris@0
|
40 * After the stream has been detached, the stream is in an unusable state.
|
Chris@0
|
41 *
|
Chris@0
|
42 * @return resource|null Underlying PHP stream, if any
|
Chris@0
|
43 */
|
Chris@0
|
44 public function detach();
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * Get the size of the stream if known.
|
Chris@0
|
48 *
|
Chris@0
|
49 * @return int|null Returns the size in bytes if known, or null if unknown.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function getSize();
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Returns the current position of the file read/write pointer
|
Chris@0
|
55 *
|
Chris@0
|
56 * @return int Position of the file pointer
|
Chris@0
|
57 * @throws \RuntimeException on error.
|
Chris@0
|
58 */
|
Chris@0
|
59 public function tell();
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Returns true if the stream is at the end of the stream.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @return bool
|
Chris@0
|
65 */
|
Chris@0
|
66 public function eof();
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Returns whether or not the stream is seekable.
|
Chris@0
|
70 *
|
Chris@0
|
71 * @return bool
|
Chris@0
|
72 */
|
Chris@0
|
73 public function isSeekable();
|
Chris@0
|
74
|
Chris@0
|
75 /**
|
Chris@0
|
76 * Seek to a position in the stream.
|
Chris@0
|
77 *
|
Chris@0
|
78 * @link http://www.php.net/manual/en/function.fseek.php
|
Chris@0
|
79 * @param int $offset Stream offset
|
Chris@0
|
80 * @param int $whence Specifies how the cursor position will be calculated
|
Chris@0
|
81 * based on the seek offset. Valid values are identical to the built-in
|
Chris@0
|
82 * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
|
Chris@0
|
83 * offset bytes SEEK_CUR: Set position to current location plus offset
|
Chris@0
|
84 * SEEK_END: Set position to end-of-stream plus offset.
|
Chris@0
|
85 * @throws \RuntimeException on failure.
|
Chris@0
|
86 */
|
Chris@0
|
87 public function seek($offset, $whence = SEEK_SET);
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * Seek to the beginning of the stream.
|
Chris@0
|
91 *
|
Chris@0
|
92 * If the stream is not seekable, this method will raise an exception;
|
Chris@0
|
93 * otherwise, it will perform a seek(0).
|
Chris@0
|
94 *
|
Chris@0
|
95 * @see seek()
|
Chris@0
|
96 * @link http://www.php.net/manual/en/function.fseek.php
|
Chris@0
|
97 * @throws \RuntimeException on failure.
|
Chris@0
|
98 */
|
Chris@0
|
99 public function rewind();
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Returns whether or not the stream is writable.
|
Chris@0
|
103 *
|
Chris@0
|
104 * @return bool
|
Chris@0
|
105 */
|
Chris@0
|
106 public function isWritable();
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Write data to the stream.
|
Chris@0
|
110 *
|
Chris@0
|
111 * @param string $string The string that is to be written.
|
Chris@0
|
112 * @return int Returns the number of bytes written to the stream.
|
Chris@0
|
113 * @throws \RuntimeException on failure.
|
Chris@0
|
114 */
|
Chris@0
|
115 public function write($string);
|
Chris@0
|
116
|
Chris@0
|
117 /**
|
Chris@0
|
118 * Returns whether or not the stream is readable.
|
Chris@0
|
119 *
|
Chris@0
|
120 * @return bool
|
Chris@0
|
121 */
|
Chris@0
|
122 public function isReadable();
|
Chris@0
|
123
|
Chris@0
|
124 /**
|
Chris@0
|
125 * Read data from the stream.
|
Chris@0
|
126 *
|
Chris@0
|
127 * @param int $length Read up to $length bytes from the object and return
|
Chris@0
|
128 * them. Fewer than $length bytes may be returned if underlying stream
|
Chris@0
|
129 * call returns fewer bytes.
|
Chris@0
|
130 * @return string Returns the data read from the stream, or an empty string
|
Chris@0
|
131 * if no bytes are available.
|
Chris@0
|
132 * @throws \RuntimeException if an error occurs.
|
Chris@0
|
133 */
|
Chris@0
|
134 public function read($length);
|
Chris@0
|
135
|
Chris@0
|
136 /**
|
Chris@0
|
137 * Returns the remaining contents in a string
|
Chris@0
|
138 *
|
Chris@0
|
139 * @return string
|
Chris@0
|
140 * @throws \RuntimeException if unable to read or an error occurs while
|
Chris@0
|
141 * reading.
|
Chris@0
|
142 */
|
Chris@0
|
143 public function getContents();
|
Chris@0
|
144
|
Chris@0
|
145 /**
|
Chris@0
|
146 * Get stream metadata as an associative array or retrieve a specific key.
|
Chris@0
|
147 *
|
Chris@0
|
148 * The keys returned are identical to the keys returned from PHP's
|
Chris@0
|
149 * stream_get_meta_data() function.
|
Chris@0
|
150 *
|
Chris@0
|
151 * @link http://php.net/manual/en/function.stream-get-meta-data.php
|
Chris@0
|
152 * @param string $key Specific metadata to retrieve.
|
Chris@0
|
153 * @return array|mixed|null Returns an associative array if no key is
|
Chris@0
|
154 * provided. Returns a specific key value if a key is provided and the
|
Chris@0
|
155 * value is found, or null if the key is not found.
|
Chris@0
|
156 */
|
Chris@0
|
157 public function getMetadata($key = null);
|
Chris@0
|
158 }
|