JSONEncoder
About 1 min
JSONEncoder
class JSONEncoder implements \Hazaar\RPC\Interface\EncoderImplements: Hazaar\RPC\Interface\Encoder
Methods
getContentType
Returns the MIME content type for JSON data.
public getContentType(): stringReturns: string
request
Creates a JSON-RPC request string.
public request(string $method, array $params, null|int|string $requestID): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | the name of the method to be invoked |
$params | array | The parameters to be passed to the method. Defaults to an empty array. |
$requestID | null | int |
notification
Creates a JSON-RPC 2.0 notification message.
public notification(string $method, array $params): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | the name of the method to invoke |
$params | array | optional parameters to include with the notification |
response
Generates a JSON-RPC 2.0 response string.
public response(mixed $result, null|int|string $requestID): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$result | mixed | the result data to be returned in the response |
$requestID | null | int |
parse
Parses a JSON-RPC 2.0 message and extracts the method and parameters or result/error.
public parse(string $json, ?string $method, null|int|string $requestID): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$json | string | the JSON string to parse |
$method | string | |
$requestID | null | int |
error
Generates a JSON-RPC 2.0 error response.
public error(\Throwable $exception, null|int|string $requestID): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$exception | Throwable | |
$requestID | null | int |
encodeResponse
Encodes a JSON-RPC 2.0 response array into a Response object.
public encodeResponse(mixed $response): ResponseReturns: Hazaar\Controller\Response
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | mixed | The response data to encode. Must be an array containing a valid JSON-RPC 2.0 response structure. |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000