diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-11-24 04:58:38 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-11-24 04:58:38 +0900 |
| commit | 67094790d2d9db5c99e7c136f49061a78698e57d (patch) | |
| tree | 02feb966e74c7c2d1b6a77d8310502aa9758649b /vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php | |
| parent | a071111365f9760b2f97fa3f6e12aee9f75dd15d (diff) | |
| download | nil.ninja-67094790d2d9db5c99e7c136f49061a78698e57d.tar.gz nil.ninja-67094790d2d9db5c99e7c136f49061a78698e57d.tar.zst nil.ninja-67094790d2d9db5c99e7c136f49061a78698e57d.zip | |
Add vhosts/t/phpcon-kagawa-2025/
Diffstat (limited to 'vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php')
| -rw-r--r-- | vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php b/vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php new file mode 100644 index 0000000..adcdd7d --- /dev/null +++ b/vhosts/t/phpcon-kagawa-2025/src/Http/Stream.php @@ -0,0 +1,110 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\TinyPhpHttpd\Http; + +use Psr\Http\Message\StreamInterface; + +final class Stream implements StreamInterface +{ + private string $content; + + private int $position = 0; + + public function __construct(string $content = '') + { + $this->content = $content; + } + + public function __toString(): string + { + return $this->content; + } + + public function close(): void + { + $this->content = ''; + $this->position = 0; + } + + public function detach(): null + { + return null; + } + + public function getSize(): int + { + return strlen($this->content); + } + + public function tell(): int + { + return $this->position; + } + + public function eof(): bool + { + return $this->position >= strlen($this->content); + } + + public function isSeekable(): bool + { + return true; + } + + public function seek(int $offset, int $whence = SEEK_SET): void + { + switch ($whence) { + case SEEK_SET: + $this->position = $offset; + break; + case SEEK_CUR: + $this->position += $offset; + break; + case SEEK_END: + $this->position = strlen($this->content) + $offset; + break; + } + } + + public function rewind(): void + { + $this->position = 0; + } + + public function isWritable(): bool + { + return true; + } + + public function write(string $string): int + { + $this->content .= $string; + return strlen($string); + } + + public function isReadable(): bool + { + return true; + } + + public function read(int $length): string + { + $result = substr($this->content, $this->position, $length); + $this->position += strlen($result); + return $result; + } + + public function getContents(): string + { + $result = substr($this->content, $this->position); + $this->position = strlen($this->content); + return $result; + } + + public function getMetadata(?string $key = null): ?array + { + return $key === null ? [] : null; + } +} |
