You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
I'm trying to play with SSE (Server Side Events) and I need help to figure out how I can send an SSE response with Diactoros ?
I tried to create a new response type as following:
class SseResponse extends Response {
use InjectContentTypeTrait;
/**
* Create an HTML response.
*
* Produces an HTML response with a Content-Type of text/html and a default
* status of 200.
*
* @param string|StreamInterface $html HTML or stream for the message body.
* @param int $status Integer status code for the response; 200 by default.
* @param array $headers Array of headers to use at initialization.
* @throws InvalidArgumentException if $html is neither a string or stream.
*/
public function __construct( $callback, array $headers = [] ) {
$this->callback = $callback;
parent::__construct(
$this->createBody(),
200,
$this->injectContentType( 'text/event-stream', $headers )
);
}
/**
* Create the message body.
*
* @param string|StreamInterface $html
* @return StreamInterface
* @throws InvalidArgumentException if $html is neither a string or stream.
*/
private function createBody() {
$body = new Stream( 'php://temp', 'wb+' );
$body->rewind();
return $body;
}
public function getBody() {
call_user_func( $this->callback );
}
}
But without success. Do you have any idea how I can handle this kind of response ?
Regards,
The text was updated successfully, but these errors were encountered:
Hi,
I'm trying to play with SSE (Server Side Events) and I need help to figure out how I can send an SSE response with Diactoros ?
I tried to create a new response type as following:
But without success. Do you have any idea how I can handle this kind of response ?
Regards,
The text was updated successfully, but these errors were encountered: