Parser
in package
uses
EncoderAware, LoggerAware
Tags
Table of Contents
Constants
- RETURN_JSONRPCVALS = 'jsonrpcvals'
- RETURN_PHP = 'phpvals'
Properties
- $_xh : mixed
- $encoder : mixed
- $returnTypeOverride : mixed
Methods
- decodeJson() : Request|Response|Value|false
- Convert the json representation of a json-rpc method call, json-rpc method response or single json value into the appropriate object (a.k.a. deserialize).
- forceReturnType() : mixed
- getEncoder() : mixed
- guessEncoding() : string
- The relevant RFC is https://www.rfc-editor.org/rfc/rfc8259#section-8.1, which says we SHOULD always use UTF-8.
- parseRequest() : false|array<string|int, mixed>
- Parse a json string, expected to be in json-rpc request format.
- parseResponse() : false|array<string|int, mixed>
- Parse a json string, expected to be in json-rpc response format.
- php2JsonrpcType() : string
- Given a string defining a php type or phpxmlrpc type (loosely defined: strings accepted come from phpdoc blocks), return corresponding phpxmlrpc type.
- setEncoder() : mixed
- convertEncoding() : void
- Recursively convert charset encoding of data gotten from json decoding.
- jsonDecode() : mixed
- Carries out the 'json-decoding' part of the parsing, including charset transcoding; resets $this->_xh; sets $this->_xh['isf'] on errors.
Constants
RETURN_JSONRPCVALS
public
mixed
RETURN_JSONRPCVALS
= 'jsonrpcvals'
RETURN_PHP
public
mixed
RETURN_PHP
= 'phpvals'
Properties
$_xh
public
mixed
$_xh
= array(
// 3: json parsing fault, 2: invalid json-rpc, 1: fault response
'isf' => 0,
'isf_reason' => '',
'value' => null,
'method' => false,
'params' => array(),
'pt' => array(),
'id' => null,
'jsonrpc_version' => \PhpXmlRpc\JsonRpc\PhpJsonRpc::VERSION_1_0,
)
Tags
$encoder
protected
static mixed
$encoder
$returnTypeOverride
protected
mixed
$returnTypeOverride
= null
Methods
decodeJson()
Convert the json representation of a json-rpc method call, json-rpc method response or single json value into the appropriate object (a.k.a. deserialize).
public
decodeJson(string $jsonVal[, array<string|int, mixed> $options = array() ]) : Request|Response|Value|false
Please note that there is no way to distinguish the serialized representation of a single json val of type object which has the 3 appropriate members from the serialization of a method call or method response. In such a case, the function will return a json-rpc Request or json-rpc Response
Parameters
- $jsonVal : string
- $options : array<string|int, mixed> = array()
-
includes source_charset, target_charset
Return values
Request|Response|Value|false —false on error, or an instance of Value, Response or Request
forceReturnType()
public
forceReturnType(mixed $returnType) : mixed
Parameters
- $returnType : mixed
getEncoder()
public
getEncoder() : mixed
guessEncoding()
The relevant RFC is https://www.rfc-editor.org/rfc/rfc8259#section-8.1, which says we SHOULD always use UTF-8.
public
static guessEncoding([string $httpHeader = '' ][, string $jsonChunk = '' ]) : string
We opt instead to "respect" - but log as error - any charset declared via the content-type http header or the BOM...
Parameters
- $httpHeader : string = ''
- $jsonChunk : string = ''
-
at least the first 4 bytes are required
Tags
Return values
stringparseRequest()
Parse a json string, expected to be in json-rpc request format.
public
parseRequest(mixed $data[, string $returnType = self::RETURN_JSONRPCVALS ][, array<string|int, mixed> $options = array() ]) : false|array<string|int, mixed>
Parameters
- $data : mixed
- $returnType : string = self::RETURN_JSONRPCVALS
- $options : array<string|int, mixed> = array()
-
integer keys: options passed to the inner json parser string keys:
- source_charset (string)
- target_charset (string)
Tags
Return values
false|array<string|int, mixed>parseResponse()
Parse a json string, expected to be in json-rpc response format.
public
parseResponse(mixed $data[, string $returnType = self::RETURN_JSONRPCVALS ][, array<string|int, mixed> $options = array() ]) : false|array<string|int, mixed>
Parameters
- $data : mixed
- $returnType : string = self::RETURN_JSONRPCVALS
- $options : array<string|int, mixed> = array()
Tags
Return values
false|array<string|int, mixed>php2JsonrpcType()
Given a string defining a php type or phpxmlrpc type (loosely defined: strings accepted come from phpdoc blocks), return corresponding phpxmlrpc type.
public
php2JsonrpcType(string $phpType) : string
NB: for php 'resource' types returns empty string, since resources cannot be serialized; for php class names returns 'struct', since php objects can be serialized as json structs; for php arrays always return 'array', even though arrays sometimes serialize as json structs
Parameters
- $phpType : string
Return values
stringsetEncoder()
public
static setEncoder(mixed $encoder) : mixed
Parameters
- $encoder : mixed
convertEncoding()
Recursively convert charset encoding of data gotten from json decoding.
protected
convertEncoding(mixed &$data, false|string $targetCharset) : void
Parameters
- $data : mixed
- $targetCharset : false|string
-
when false, use utf8_decode instead of mb_convert_encoding
jsonDecode()
Carries out the 'json-decoding' part of the parsing, including charset transcoding; resets $this->_xh; sets $this->_xh['isf'] on errors.
protected
jsonDecode(string $data[, array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $data : string
- $options : array<string|int, mixed> = array()