File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 
0003 namespace Psr\Http\Message;
0004 
0005 /**
0006  * Describes a data stream.
0007  *
0008  * Typically, an instance will wrap a PHP stream; this interface provides
0009  * a wrapper around the most common operations, including serialization of
0010  * the entire stream to a string.
0011  */
0012 interface StreamInterface
0013 {
0014     /**
0015      * Reads all data from the stream into a string, from the beginning to end.
0016      *
0017      * This method MUST attempt to seek to the beginning of the stream before
0018      * reading data and read the stream until the end is reached.
0019      *
0020      * Warning: This could attempt to load a large amount of data into memory.
0021      *
0022      * This method MUST NOT raise an exception in order to conform with PHP's
0023      * string casting operations.
0024      *
0025      * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
0026      * @return string
0027      */
0028     public function __toString();
0029 
0030     /**
0031      * Closes the stream and any underlying resources.
0032      *
0033      * @return void
0034      */
0035     public function close();
0036 
0037     /**
0038      * Separates any underlying resources from the stream.
0039      *
0040      * After the stream has been detached, the stream is in an unusable state.
0041      *
0042      * @return resource|null Underlying PHP stream, if any
0043      */
0044     public function detach();
0045 
0046     /**
0047      * Get the size of the stream if known.
0048      *
0049      * @return int|null Returns the size in bytes if known, or null if unknown.
0050      */
0051     public function getSize();
0052 
0053     /**
0054      * Returns the current position of the file read/write pointer
0055      *
0056      * @return int Position of the file pointer
0057      * @throws \RuntimeException on error.
0058      */
0059     public function tell();
0060 
0061     /**
0062      * Returns true if the stream is at the end of the stream.
0063      *
0064      * @return bool
0065      */
0066     public function eof();
0067 
0068     /**
0069      * Returns whether or not the stream is seekable.
0070      *
0071      * @return bool
0072      */
0073     public function isSeekable();
0074 
0075     /**
0076      * Seek to a position in the stream.
0077      *
0078      * @link http://www.php.net/manual/en/function.fseek.php
0079      * @param int $offset Stream offset
0080      * @param int $whence Specifies how the cursor position will be calculated
0081      *     based on the seek offset. Valid values are identical to the built-in
0082      *     PHP $whence values for `fseek()`.  SEEK_SET: Set position equal to
0083      *     offset bytes SEEK_CUR: Set position to current location plus offset
0084      *     SEEK_END: Set position to end-of-stream plus offset.
0085      * @throws \RuntimeException on failure.
0086      */
0087     public function seek($offset, $whence = SEEK_SET);
0088 
0089     /**
0090      * Seek to the beginning of the stream.
0091      *
0092      * If the stream is not seekable, this method will raise an exception;
0093      * otherwise, it will perform a seek(0).
0094      *
0095      * @see seek()
0096      * @link http://www.php.net/manual/en/function.fseek.php
0097      * @throws \RuntimeException on failure.
0098      */
0099     public function rewind();
0100 
0101     /**
0102      * Returns whether or not the stream is writable.
0103      *
0104      * @return bool
0105      */
0106     public function isWritable();
0107 
0108     /**
0109      * Write data to the stream.
0110      *
0111      * @param string $string The string that is to be written.
0112      * @return int Returns the number of bytes written to the stream.
0113      * @throws \RuntimeException on failure.
0114      */
0115     public function write($string);
0116 
0117     /**
0118      * Returns whether or not the stream is readable.
0119      *
0120      * @return bool
0121      */
0122     public function isReadable();
0123 
0124     /**
0125      * Read data from the stream.
0126      *
0127      * @param int $length Read up to $length bytes from the object and return
0128      *     them. Fewer than $length bytes may be returned if underlying stream
0129      *     call returns fewer bytes.
0130      * @return string Returns the data read from the stream, or an empty string
0131      *     if no bytes are available.
0132      * @throws \RuntimeException if an error occurs.
0133      */
0134     public function read($length);
0135 
0136     /**
0137      * Returns the remaining contents in a string
0138      *
0139      * @return string
0140      * @throws \RuntimeException if unable to read or an error occurs while
0141      *     reading.
0142      */
0143     public function getContents();
0144 
0145     /**
0146      * Get stream metadata as an associative array or retrieve a specific key.
0147      *
0148      * The keys returned are identical to the keys returned from PHP's
0149      * stream_get_meta_data() function.
0150      *
0151      * @link http://php.net/manual/en/function.stream-get-meta-data.php
0152      * @param string $key Specific metadata to retrieve.
0153      * @return array|mixed|null Returns an associative array if no key is
0154      *     provided. Returns a specific key value if a key is provided and the
0155      *     value is found, or null if the key is not found.
0156      */
0157     public function getMetadata($key = null);
0158 }