final class IterableStream implements StreamInterface (View source)

Represents a one-pass response body that reads lazy producer chunks without assembling the full content in memory

Methods

__construct(Closure $producer)

Initializes a one-pass producer that lazily yields string chunks while the stream is read

from(callable $producer)

Creates a body whose producer is not invoked until its first read

string

Reads the remaining content for PSR-7 string conversion, which may use memory proportional to the body size

string
void
close()

Stops the producer and discards all unread chunks

void
null
detach()

Detaches the one-pass producer and returns null because this body has no resource handle

null
int|null

Returns null because the producer total size is not known in advance

int|null
int
tell()

Returns the number of bytes read from this one-pass stream

int
bool
eof()

Reports whether the producer has no remaining chunks or the stream was closed

bool
bool

Reports false because a generator producer cannot return to an earlier position

bool
void
seek(int $offset, int $whence = SEEK_SET)

Rejects repositioning within the one-pass stream

void
void
rewind()

Rejects rewinding the one-pass producer

void
bool

Reports false because response bodies created from producers do not accept writes

bool
int
write(string $string)

Rejects writes to the read-only response body

int
bool

Reports whether the stream remains open for reading

bool
string
read(int $length)

Reads at most the requested byte count while retaining only the current chunk and its unread remainder

string
string

Reads all remaining chunks, a PSR-7 operation that may use memory proportional to the body size

string
mixed
getMetadata(string|null $key = null)

Returns metadata for the one-pass read-only producer

mixed

Details

__construct

__construct(Closure $producer)

Initializes a one-pass producer that lazily yields string chunks while the stream is read

Parameters

Closure $producer

from

static IterableStream from(callable $producer)

Creates a body whose producer is not invoked until its first read

Parameters

callable $producer

Return Value

IterableStream

__toString

string __toString()

Reads the remaining content for PSR-7 string conversion, which may use memory proportional to the body size

Return Value

string

close

void close()

Stops the producer and discards all unread chunks

Return Value

void

detach

null detach()

Detaches the one-pass producer and returns null because this body has no resource handle

Return Value

null

getSize

int|null getSize()

Returns null because the producer total size is not known in advance

Return Value

int|null

tell

int tell()

Returns the number of bytes read from this one-pass stream

Return Value

int

eof

bool eof()

Reports whether the producer has no remaining chunks or the stream was closed

Return Value

bool

isSeekable

bool isSeekable()

Reports false because a generator producer cannot return to an earlier position

Return Value

bool

seek

void seek(int $offset, int $whence = SEEK_SET)

Rejects repositioning within the one-pass stream

Parameters

int $offset
int $whence

Return Value

void

rewind

void rewind()

Rejects rewinding the one-pass producer

Return Value

void

isWritable

bool isWritable()

Reports false because response bodies created from producers do not accept writes

Return Value

bool

write

int write(string $string)

Rejects writes to the read-only response body

Parameters

string $string

Return Value

int

isReadable

bool isReadable()

Reports whether the stream remains open for reading

Return Value

bool

read

string read(int $length)

Reads at most the requested byte count while retaining only the current chunk and its unread remainder

Parameters

int $length

Return Value

string

getContents

string getContents()

Reads all remaining chunks, a PSR-7 operation that may use memory proportional to the body size

Return Value

string

getMetadata

mixed getMetadata(string|null $key = null)

Returns metadata for the one-pass read-only producer

Parameters

string|null $key

Return Value

mixed