Factory
2 months ago
Interfaces
2 months ago
Cookies.php
2 months ago
Environment.php
2 months ago
Header.php
2 months ago
Headers.php
2 months ago
Message.php
2 months ago
NonBufferedBody.php
2 months ago
Request.php
2 months ago
Response.php
2 months ago
Stream.php
2 months ago
UploadedFile.php
2 months ago
Uri.php
2 months ago
NonBufferedBody.php
154 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Slim Framework (https://slimframework.com) |
| 5 | * |
| 6 | * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License) |
| 7 | */ |
| 8 | |
| 9 | declare(strict_types=1); |
| 10 | |
| 11 | namespace Slim\Psr7; |
| 12 | |
| 13 | use AmeliaVendor\Psr\Http\Message\StreamInterface; |
| 14 | use RuntimeException; |
| 15 | |
| 16 | use function flush; |
| 17 | use function ob_get_clean; |
| 18 | use function ob_get_level; |
| 19 | use function strlen; |
| 20 | |
| 21 | use const SEEK_SET; |
| 22 | |
| 23 | class NonBufferedBody implements StreamInterface |
| 24 | { |
| 25 | /** |
| 26 | * {@inheritdoc} |
| 27 | */ |
| 28 | public function __toString(): string |
| 29 | { |
| 30 | return ''; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * {@inheritdoc} |
| 35 | */ |
| 36 | public function close(): void |
| 37 | { |
| 38 | throw new RuntimeException('A NonBufferedBody is not closable.'); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * {@inheritdoc} |
| 43 | */ |
| 44 | public function detach() |
| 45 | { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritdoc} |
| 51 | */ |
| 52 | public function getSize(): ?int |
| 53 | { |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritdoc} |
| 59 | */ |
| 60 | public function tell(): int |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritdoc} |
| 67 | */ |
| 68 | public function eof(): bool |
| 69 | { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * {@inheritdoc} |
| 75 | */ |
| 76 | public function isSeekable(): bool |
| 77 | { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * {@inheritdoc} |
| 83 | */ |
| 84 | public function seek($offset, $whence = SEEK_SET): void |
| 85 | { |
| 86 | throw new RuntimeException('A NonBufferedBody is not seekable.'); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * {@inheritdoc} |
| 91 | */ |
| 92 | public function rewind(): void |
| 93 | { |
| 94 | throw new RuntimeException('A NonBufferedBody is not rewindable.'); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * {@inheritdoc} |
| 99 | */ |
| 100 | public function isWritable(): bool |
| 101 | { |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * {@inheritdoc} |
| 107 | */ |
| 108 | public function write($string): int |
| 109 | { |
| 110 | $buffered = ''; |
| 111 | while (0 < ob_get_level()) { |
| 112 | $buffered = ob_get_clean() . $buffered; |
| 113 | } |
| 114 | |
| 115 | echo $buffered . $string; |
| 116 | |
| 117 | flush(); |
| 118 | |
| 119 | return strlen($string) + strlen($buffered); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * {@inheritdoc} |
| 124 | */ |
| 125 | public function isReadable(): bool |
| 126 | { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * {@inheritdoc} |
| 132 | */ |
| 133 | public function read($length): string |
| 134 | { |
| 135 | throw new RuntimeException('A NonBufferedBody is not readable.'); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * {@inheritdoc} |
| 140 | */ |
| 141 | public function getContents(): string |
| 142 | { |
| 143 | return ''; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * {@inheritdoc} |
| 148 | */ |
| 149 | public function getMetadata($key = null): ?array |
| 150 | { |
| 151 | return null; |
| 152 | } |
| 153 | } |
| 154 |