class class@anonymous {}

In this article

Methods

NameDescription
class@anonymous::stream_eof
class@anonymous::stream_open
class@anonymous::stream_read
class@anonymous::stream_seek
class@anonymous::stream_set_option
class@anonymous::stream_stat
class@anonymous::stream_tell
class@anonymous::stream_truncate
class@anonymous::stream_write

Source

$wrapper ?? \stream_wrapper_register('Nyholm-Psr7-Zval', $wrapper = \get_class(new class
{
    public $context;
    private $data;
    private $position = 0;
    public function stream_open(): bool
    {
        $this->data = \stream_context_get_options($this->context)['Nyholm-Psr7-Zval']['data'];
        \stream_context_set_option($this->context, 'Nyholm-Psr7-Zval', 'data', null);
        return \true;
    }
    public function stream_read(int $count): string
    {
        $result = \substr($this->data, $this->position, $count);
        $this->position += \strlen($result);
        return $result;
    }
    public function stream_write(string $data): int
    {
        $this->data = \substr_replace($this->data, $data, $this->position, \strlen($data));
        $this->position += \strlen($data);
        return \strlen($data);
    }
    public function stream_tell(): int
    {
        return $this->position;
    }
    public function stream_eof(): bool
    {
        return \strlen($this->data) <= $this->position;
    }
    public function stream_stat(): array
    {
        return [
            'mode' => 33206,
            // POSIX_S_IFREG | 0666
            'nlink' => 1,
            'rdev' => -1,
            'size' => \strlen($this->data),
            'blksize' => -1,
            'blocks' => -1,
        ];
    }
    public function stream_seek(int $offset, int $whence): bool
    {
        if (\SEEK_SET === $whence && (0 <= $offset && \strlen($this->data) >= $offset)) {
            $this->position = $offset;
        } elseif (\SEEK_CUR === $whence && 0 <= $offset) {
            $this->position += $offset;
        } elseif (\SEEK_END === $whence && (0 > $offset && 0 <= $offset = \strlen($this->data) + $offset)) {
            $this->position = $offset;
        } else {
            return \false;
        }
        return \true;
    }
    public function stream_set_option(): bool
    {
        return \true;
    }
    public function stream_truncate(int $new_size): bool
    {
        if ($new_size) {
            $this->data = \substr($this->data, 0, $new_size);
            $this->position = \min($this->position, $new_size);
        } else {
            $this->data = '';
            $this->position = 0;
        }
        return \true;
    }
}));

User Contributed Notes

You must log in before being able to contribute a note or feedback.