-
Notifications
You must be signed in to change notification settings - Fork 0
JsonStream
Class JsonStream.
Provides a JSON-specific stream implementation, extending Nyholm's PSR-7 Stream. This class SHALL encapsulate a JSON-encoded payload within an in-memory PHP stream, while retaining the original decoded payload for convenient retrieval.
Implementations of this class MUST properly handle JSON encoding errors and SHALL explicitly prohibit the inclusion of resource types within the JSON payload.
- Full name:
\FastForward\Http\Message\JsonStream - Parent class:
Stream - This class is marked as final and can't be subclassed
- This class implements:
\FastForward\Http\Message\PayloadStreamInterface - This class is a Final class
| Constant | Visibility | Type | Value |
|---|---|---|---|
ENCODING_OPTIONS |
public | int | \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE |
Constructs a new JsonStream instance with the provided payload.
public __construct(mixed $payload = [], int $encodingOptions = \self::ENCODING_OPTIONS): mixedThe payload SHALL be JSON-encoded and written to an in-memory stream. The original payload is retained in its decoded form for later access via getPayload().
Parameters:
| Parameter | Type | Description |
|---|---|---|
$payload |
mixed | The data to encode as JSON. MUST be JSON-encodable. Resources are explicitly prohibited. |
$encodingOptions |
int | Optional JSON encoding flags. If omitted, ENCODING_OPTIONS will be applied. |
Retrieves the decoded payload associated with the stream.
public getPayload(): mixedThis method SHALL return the original JSON-encodable payload provided during construction or via withPayload().
Return Value:
the decoded payload
Returns a new instance of the stream with the specified payload.
public withPayload(mixed $payload): selfThis method MUST return a new JsonStream instance with the body replaced by a stream containing the JSON-encoded form of the new payload. The current instance SHALL remain unchanged.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$payload |
mixed | the new JSON-encodable payload |
Return Value:
a new JsonStream instance containing the updated payload