JSONRPC 1.0.0

Parser
in package
uses EncoderAware, DeprecationLogger

Tags
see
https://www.jsonrpc.org/specification_v1,

https://www.jsonrpc.org/specification

todo

add support for jsonclass

todo

add support for json-rpc 1.1 ? see: https://jsonrpc.org/historical/json-rpc-1-1-wd.html and https://jsonrpc.org/historical/json-rpc-1-1-alt.html

todo

add a ParseValue method ?

todo

add a Parse method (same as XMLParser) ?

todo

add a constructor which can be used to set default options

todo

introduce $responseClass, to allow subclasses to produce different types of response?

Table of Contents

Constants

RETURN_JSONRPCVALS  = 'jsonrpcvals'
RETURN_PHP  = 'phpvals'

Properties

$_xh  : mixed
$encoder  : mixed
$returnTypeOverride  : mixed

Methods

__get()  : mixed
__isset()  : mixed
__set()  : mixed
__unset()  : mixed
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()  : array<string|int, mixed>
Parse a json string, expected to be in json-rpc request format.
parseResponse()  : 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
xmlrpc_se_any()  : void
xml parser handler function for opening element tags.
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

protected 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, 'is_multicall' => false, )
Tags
see
XMLParser

$returnTypeOverride

protected mixed $returnTypeOverride = null

Methods

__get()

public & __get(mixed $name) : mixed
Parameters
$name : mixed

__isset()

public __isset(mixed $name) : mixed
Parameters
$name : mixed

__set()

public __set(mixed $name, mixed $value) : mixed
Parameters
$name : mixed
$value : mixed

__unset()

public __unset(mixed $name) : mixed
Parameters
$name : mixed

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

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
todo

should we return 'UTF-8' or '' by default?

Return values
string

parseRequest()

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() ]) : 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
throws
Exception

this can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)

todo

checks missing:

  • no extra members in request
Return values
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() ]) : array<string|int, mixed>
Parameters
$data : mixed
$returnType : string = self::RETURN_JSONRPCVALS
$options : array<string|int, mixed> = array()
Tags
todo

checks missing:

  • no extra members in response
Return values
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
string

setEncoder()

public static setEncoder(mixed $encoder) : mixed
Parameters
$encoder : mixed

xmlrpc_se_any()

xml parser handler function for opening element tags.

public xmlrpc_se_any(resource $parser, mixed $name, mixed $attrs) : void

Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.

Parameters
$parser : resource
$name : mixed
$attrs : 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()

        
On this page

Search results