CallbackStream
A response body that is PRODUCED at emit time by a callback, so a handler can stream (greenhouse evidence/0472). The runtime's ordinary emission materializes a body — `echo (string) $body` — which buffers the whole response before a byte reaches the client. That is correct for a normal page and fatal for `text/event-stream`: an SSE feed must write and flush events over the life of the connection. A `CallbackStream` carries a callback INSTEAD of bytes; {@see ResponseEmitter} recognizes it and runs the callback (which writes to the output and flushes) rather than stringifying it. The callback owns the loop and the flushing; this class is only the marker that carries it through the PSR-7 response. It is deliberately not a readable/materializable stream: stringifying it yields an empty string, so an app still on the buffered emission path (not the {@see ResponseEmitter}) serves nothing rather than a broken half-response — a loud "you must emit this with the streaming emitter", not a silent corruption.
CallbackStream::__construct()
public function __construct(Closure $callback):Parameters
| Name | Type | Description |
|---|---|---|
| $callback | \Closure(): void | Writes the body to the output (echo + flush), owning any loop. |
CallbackStream::callback()
public function callback(): callableThe callback {@see ResponseEmitter} invokes to stream the body.
CallbackStream::__toString()
public function __toString(): stringNot materializable: the body only exists when streamed by the emitter.
CallbackStream::close()
public function close(): voidNo underlying resource to close.
CallbackStream::detach()
public function detach():No underlying resource to detach.
CallbackStream::getSize()
public function getSize(): ?intUnknown until streamed, so unknown by contract.
CallbackStream::tell()
public function tell(): intNothing to point into.
CallbackStream::eof()
public function eof(): boolAlways at the end: there is no buffer to read from.
CallbackStream::isSeekable()
public function isSeekable(): boolA callback body cannot be rewound.
CallbackStream::seek()
public function seek(int $offset, int $whence = Milpa\Runtime\Http\SEEK_SET): voidNot seekable: the body is produced once, by the emitter.
Parameters
| Name | Type | Description |
|---|---|---|
| $offset | int | |
| $whence | int |
CallbackStream::rewind()
public function rewind(): voidNot seekable: the body is produced once, by the emitter.
CallbackStream::isWritable()
public function isWritable(): boolThe content comes from the callback, not from writes to this stream.
CallbackStream::write()
public function write(string $string): intNot writable: the content is produced by the callback.
Parameters
| Name | Type | Description |
|---|---|---|
| $string | string |
CallbackStream::isReadable()
public function isReadable(): boolThere is nothing to read: the body is streamed by the emitter, not read here.
CallbackStream::read()
public function read(int $length): stringNothing to read: the body only exists when streamed by the emitter.
Parameters
| Name | Type | Description |
|---|---|---|
| $length | int |
CallbackStream::getContents()
public function getContents(): stringNot materializable: the body only exists when streamed by the emitter.
CallbackStream::getMetadata()
public function getMetadata(?string $key = null):No metadata: this carries a callback, not a stream resource.
Parameters
| Name | Type | Description |
|---|---|---|
| $key | (string | null) |