-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNullStream.php
74 lines (56 loc) · 1.37 KB
/
NullStream.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
<?php
declare(strict_types = 1);
namespace Watchr\Console\Streams;
use RuntimeException;
use Watchr\Console\Contracts\Streams\StreamInterface;
/**
* Does not store any data written to it.
*
* @link https://github.com/guzzle/streams/blob/master/src/NullStream.php
*/
class NullStream implements StreamInterface {
public function __toString(): string {
return '';
}
public function getContents(): string {
return '';
}
public function close(): void {}
public function detach(): mixed {
return null;
}
public function attach($stream): void {
throw new RuntimeException('Cannot attach stream');
}
public function getSize(): int|null {
return 0;
}
public function isReadable(): bool {
return true;
}
public function isWritable(): bool {
return true;
}
public function isSeekable(): bool {
return true;
}
public function eof(): bool {
return true;
}
public function tell(): int {
return 0;
}
public function seek(int $offset, int $whence = SEEK_SET): bool {
return false;
}
public function read(int $length): string {
throw new RuntimeException('Failed to read stream');
}
public function write(string $data): int {
return strlen($data);
}
public function getMetadata(string $key = null): mixed {
return $key === null ? null : [];
}
public function readOnly(): void {}
}