-
Notifications
You must be signed in to change notification settings - Fork 0
/
StreamInterface.php
148 lines (130 loc) · 4.53 KB
/
StreamInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
declare(strict_types = 1);
namespace Watchr\Console\Contracts\Streams;
use Stringable;
/**
* Describes a stream instance.
*
* @link https://github.com/guzzle/streams/blob/master/src/StreamInterface.php
*/
interface StreamInterface extends Stringable {
/**
* Attempts to seek to the beginning of the stream and reads all data into
* a string until the end of the stream is reached.
*
* Warning: This could attempt to load a large amount of data into memory.
*/
public function __toString(): string;
/**
* Closes the stream and any underlying resources.
*/
public function close(): void;
/**
* Separates any underlying resources from the stream.
*
* After the underlying resource has been detached, the stream object is in
* an unusable state. If you wish to use a Stream object as a PHP stream
* but keep the Stream object in a consistent state, use
* {@see GuzzleHttp\Stream\GuzzleStreamWrapper::getResource}.
*
* @return resource|null Returns the underlying PHP stream resource or null
* if the Stream object did not utilize an underlying
* stream resource.
*/
public function detach(): mixed;
/**
* Replaces the underlying stream resource with the provided stream.
*
* Use this method to replace the underlying stream with another; as an
* example, in server-side code, if you decide to return a file, you
* would replace the original content-oriented stream with the file
* stream.
*
* Any internal state such as caching of cursor position should be reset
* when attach() is called, as the stream has changed.
*
* @param resource $stream
*/
public function attach($stream): void;
/**
* Get the size of the stream if known, or null if unknown
*/
public function getSize(): int|null;
/**
* Returns the current position of the file read/write pointer
*
* @throws RuntimeException
*/
public function tell(): int;
/**
* Returns true if the stream is at the end of the stream.
*/
public function eof(): bool;
/**
* Returns whether or not the stream is seekable
*/
public function isSeekable(): bool;
/**
* Seek to a position in the stream
* Returns true on success or false on failure
*
* @param int $offset Stream offset
* @param int $whence Specifies how the cursor position will be calculated
* based on the seek offset. Valid values are identical
* to the built-in PHP $whence values for `fseek()`.
* SEEK_SET: Set position equal to offset bytes
* SEEK_CUR: Set position to current location plus offset
* SEEK_END: Set position to end-of-stream plus offset
*
* @link http://www.php.net/manual/en/function.fseek.php
*/
public function seek(int $offset, int $whence = SEEK_SET): bool;
/**
* Returns whether or not the stream is writable
*/
public function isWritable(): bool;
/**
* Write data to the stream
*
* @param string $string The string that is to be written.
*
* @throws RuntimeException
*
* @return int Returns the number of bytes written to the stream
*/
public function write(string $string): int;
/**
* Returns whether or not the stream is readable
*/
public function isReadable(): bool;
/**
* Read data from the stream
*
* @param int $length Read up to $length bytes from the object and return
* them. Fewer than $length bytes may be returned if
* underlying stream call returns fewer bytes.
*/
public function read(int $length): string;
/**
* Returns the remaining contents of the stream as a string.
*
* Note: this could potentially load a large amount of data into memory.
*/
public function getContents(): string;
/**
* Get stream metadata as an associative array or retrieve a specific key.
*
* The keys returned are identical to the keys returned from PHP's
* stream_get_meta_data() function.
*
* @param string $key Specific metadata to retrieve.
*
* @return array|mixed|null Returns an associative array if no key is
* no key is provided. Returns a specific key
* value if a key is provided and the value is
* found, or null if the key is not found.
* @see http://php.net/manual/en/function.stream-get-meta-data.php
*/
public function getMetadata(string $key = null): mixed;
public function readOnly(): void;
}