StreamResponse
MMO\core\server · 1 symbol · generated 30 Sep 2026
StreamResponse
StreamResponse.php:17Psr Response that reads a stream Used to retrieve files The application sends it as it reads it, a chunk at a time (render's output option): a download is not limited by php's memory.
- Namespace
MMO\core\server- Extends
- aResponse
Index
| CHUNK_SIZE | the size of what is read, then sent, at a time (render's output option) | |
| stream | ||
| ContentDisposition($name, $inline) static | A Content-Disposition header for a file named $name: an ascii name for old clients, and the real one as RFC 6266 has it (filename*), so that a quote, an accent or a line break in a name cannot … | |
| File($filename, $headers, $clientFilename) static | Create a Stream response using a local file | |
| getBody() | Gets the body of the message. | |
| getContentType($single) | Prefers an explicitly-set 'Content-Type' header (tWithHeaders::getContentType); falls back to the stream's own detected type (Stream::getContentType) when no header was set and the stream… | |
| getParsedBody() | Get response body decoded. | |
| JSON($filename, $clientFilename) static | Create a Stream response for a local JSON file (attachment, must-revalidate caching). | |
| lock() | Close the underlying stream, releasing its resource. | |
| logEvent($event) | ||
| output() | Send the stream as it is read, a chunk at a time: from its start when it can seek, as render reads it. | |
| render($opts) | ||
| withBody($body) | Return an instance with the specified message body. | |
| withParsedBody($data) | ||
| Zip($filename, $headers, $clientFilename) static | Create a Stream response for a local file, forced to the 'zip' content type (File for the rest). | |
| __construct($stream, $code, $reason, $headers) |
Constants1
CHUNK_SIZE
the size of what is read, then sent, at a time (render's output option)
Properties1
stream
- Type
StreamInterface
Methods14
ContentDisposition($name, $inline)
staticStreamResponse.php:110A Content-Disposition header for a file named $name: an ascii name for old clients, and the real one as RFC 6266 has it (filename*), so that a quote, an accent or a line break in a name cannot break the header.
| $name | string | |
| $inline = false | bool | if true, the browser shows the file rather than saving it |
| returns | string |
File($filename, $headers, $clientFilename)
staticStreamResponse.php:52Create a Stream response using a local file
getBody()
StreamResponse.php:202Gets the body of the message.
| returns | StreamInterface | Returns the body as a stream. |
getContentType($single)
StreamResponse.php:165Prefers an explicitly-set 'Content-Type' header (tWithHeaders::getContentType); falls back to the stream's own detected type (Stream::getContentType) when no header was set and the stream is our
- See
Streamclass. NOTE: likeStream::getContentType, this can fall through toreturn false(when no header is set AND the stream isn't aStreaminstance, e.g. a bare third-party StreamInterface) even though the return type is declaredstring|array-- harmless in practice (PHP's weak typing coerces thatfalseinto'', andgetParsedBody's only caller passes the result throughextension(), which handles''the same as any unrecognized type). UNLIKEStream::getContentType, the type is NOT widened here: this overridestWithHeaders::getContentType(viaaMessage), and PHP requires an override's return type to be covariant (a subtype) of the parent's -- adding|falsehere is not a subtype of the parent'sstring|arrayand fails at class-load time (Fatal error: Declaration ... must be compatible with ...), confirmed by testing. So this one keeps the technically-inaccuratestring|arraydeclaration; this note documents the actual (occasionally-false) behavior instead.
getParsedBody()
StreamResponse.php:176Get response body decoded.
| returns | ArrayAccess | array | null | |
| throws |
JSON($filename, $clientFilename)
staticStreamResponse.php:88Create a Stream response for a local JSON file (attachment, must-revalidate caching).
lock()
StreamResponse.php:42Close the underlying stream, releasing its resource.
| returns | void |
logEvent($event)
StreamResponse.php:37output()
StreamResponse.php:136Send the stream as it is read, a chunk at a time: from its start when it can seek, as render reads it.
| returns | void |
render($opts)
StreamResponse.php:127- See
iRenderable::render
| $opts = [] | array | output => true: the stream is sent as it is read, a chunk at a time (CHUNK_SIZE), rather than returned -- how Application::sendResponse sends it, so that a download is not limited by php's memory. Otherwise forwarded to the stream's own render() when it's our Stream class. |
| returns | string | the stream's full content, or '' when it was sent (output). |
withBody($body)
StreamResponse.php:219Return an instance with the specified message body.
| $body | StreamInterface | Body. |
| returns | self | |
| throws | When the body is not valid. |
withParsedBody($data)
StreamResponse.php:190| $data | ArrayAccess | array | null | |
| returns | Response | a new (non-stream) Response wrapping $data, keeping this response's status/headers. |
Zip($filename, $headers, $clientFilename)
staticStreamResponse.php:78Create a Stream response for a local file, forced to the 'zip' content type (File for the rest).
__construct($stream, $code, $reason, $headers)
StreamResponse.php:31Inherited members (62)
| Properties | Declared by | Description | |
|---|---|---|---|
headers | aMessage | ||
ikeys | aMessage | ||
Listeners | aMessage | ||
protocol | aMessage | ||
statusCode | aResponse | ||
statusText | aResponse | ||
stopped | aResponse |
| Methods | Declared by | Description | |
|---|---|---|---|
addHeader($name, $value) | aMessage | Append a value to a header, keeping any value(s) already set (as opposed to setHeader, which replaces). | |
AddListener($handler, $order) | aMessage | Register a listener directly (as opposed to ConnectListeners's attribute-based discovery). | |
ConnectListeners($obj) | aMessage | Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. | |
debugName() | aResponse | ||
DisconnectListeners($obj) | aMessage | Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class. | |
dispatch() | aMessage | Invoke every GetListeners listener with $this. | |
getCharset() | aMessage | ||
getContentExtension() | aMessage | ||
getExitCode() | aResponse | ||
getHeader($name) | aMessage | Retrieves a message header value by the given case-insensitive name. | |
getHeaderLine($name) | aMessage | Retrieves a comma-separated string of the values for a single header. | |
getHeaders() | aMessage | Retrieves all message header values. | |
GetListeners() | aMessage | Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep … | |
getOrigin() | aMessage | Get origin of the request by looking at 'Origin', then 'Referer', then 'Sender' in the request's headers. | |
getProtocolVersion() | aMessage | Retrieves the HTTP protocol version as a string. | |
getReasonPhrase() | aResponse | Gets the response reason phrase associated with the status code. | |
getRedirect() | aResponse | ||
getStatusCode() | aResponse | Gets the response status code. | |
getUserAgent() | aMessage | ||
hasHeader($name) | aMessage | Checks if a header exists by the given case-insensitive name. | |
HasListener($handler) | aMessage | ||
isHTML() | aMessage | ||
isIe() | aMessage | ||
isIphone() | aMessage | ||
isJSON() | aMessage | ||
isMac() | aMessage | ||
isMobile() | aMessage | ||
isOk() | aResponse | ||
isPropagationStopped() | aResponse | ||
isWindows() | aMessage | ||
RemoveListener($handler) | aMessage | Remove the last added handler from the listeners. | |
Send($args) | aMessage | Construct a new instance of this class with $args, then dispatch it to every listener. | |
setCacheControl($cache, $pragma) | aMessage | Set the Cache-Control header (and, optionally, the legacy Pragma header alongside it). | |
setContentType($type, $charset) | aMessage | Set the Content-Type header, appending a charset parameter (unless $charset is null/empty). | |
setExpires($time) | aMessage | Set the Expires header from a unix timestamp, formatted as an RFC 7231 HTTP-date. | |
setHeader($name, $value) | aMessage | Set header, replacing any previous value(s) for the same (case-insensitively matched) header name. | |
SetListenerOrder($handler, $order) | aMessage | Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here). | |
setRedirect($url, $status) | aResponse | Set a redirection call send() to actually redirect | |
setRequireAuth($realm, $type) | aResponse | Set redirection to a login/password inputbox call send() to actually redirect | |
setStatus($code, $reason) | aResponse | ||
stopPropagation() | aResponse | Prevent any remaining listener in the current dispatch chain from being called. | |
unsetHeader($name) | aMessage | Remove a header entirely. | |
withAddedHeader($name, $value) | aMessage | Return an instance with the specified header appended with the given value. | |
withCacheControl($cache, $pragma) | aMessage | Set cache control of a clone. | |
withContentType($type, $charset) | aMessage | Set content type of a clone. | |
withExpires($time) | aMessage | Set cache expire date of a clone. | |
withHeader($name, $value) | aMessage | Return an instance with the provided value replacing the specified header. | |
withHeaders($headers, $reset) | aMessage | Return a clone with every header in $headers set (through tWithHeaders::setHeader, so each value replaces any existing one for the same header name). | |
withoutHeader($name) | aMessage | Return an instance without the specified header. | |
withProtocolVersion($version) | aMessage | Return an instance with the specified HTTP protocol version. | |
withRedirect($url, $status) | aResponse | Set a redirection of a clone call send() to actually redirect | |
withRequireAuth($realm, $type) | aResponse | Set redirection to a login/password inputbox of a clone call send() to actually redirect | |
withStatus($code, $reasonPhrase) | aResponse | Return an instance with the specified status code and, optionally, reason phrase. | |
__clone() | aResponse | A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance. | |
__toString() | aResponse |