SseEvent
A single Server-Sent Events wire-format message.
Synopsis
Section titled “Synopsis”final class SseEvent
| Source | Http/Sse/SseEvent.php |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$data | string | readonly. |
$event | ?``string | readonly. |
$id | ?``string | readonly. |
$retryMs | ?``int | readonly. |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(string $data, ?string $event = null, ?string $id = null, ?int $retryMs = null): mixed
| Parameter | Type | Description |
|---|---|---|
$data | string | |
$event | ?``string | |
$id | ?``string | |
$retryMs | ?``int |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
format(): string | Renders the event as its text/event-stream representation. |
| [`of(string | array |
format()
Section titled “format()”public function format(): string
Renders the event as its text/event-stream representation.
The optional event, id and retry fields are emitted first and only when set, then the data, split into one data: line per embedded newline as the wire format requires. The result ends with the blank line that terminates the message.
Returns string
public static function of(string|array<mixed> $data, ?string $event = null, ?string $id = null, ?int $retryMs = null): SseEvent
Arrays are JSON-encoded.
| Parameter | Type | Description |
|---|---|---|
$data | `string“ | array<mixed>` |
$event | ?``string | |
$id | ?``string | |
$retryMs | ?``int |
Returns SseEvent