Documentation

JsonData
in package

JSON Interface to Cloudrexx Doctrine Database

Tags
copyright

Cloudrexx AG

author

Florian Schuetz florian.schuetz@comvation.com

author

Michael Ritter michael.ritter@comvation.com

subpackage

core_json

Table of Contents

Properties

$adapter_classes  : array<string|int, mixed>
List of adapter class names.
$adapters  : array<string|int, mixed>
List of adapters to use (they have to implement the JsonAdapter interface)
$sessionId  : string
Session id for request which we got from the login request

Methods

__construct()  : mixed
Constructor, loads adapter classes
addAdapter()  : mixed
data()  : array<string|int, mixed>
Passes JSON data to the particular adapter and returns the result Called from jsondata() or any part of Cloudrexx
getErrorData()  : array<string|int, mixed>
Returns the JSON code for a error message
getJson()  : stdClass|bool
Fetches a json response via HTTP request
getParser()  : object|callable
Returns the parser used to parse JSON Parser is either a callback function which accepts an instance of \Cx\Core\Routing\Model\Entity\Response as first argument or an object with a parse(\Cx\Core\Routing\Model\Entity\Response $response) method.
getSessionId()  : mixed
hasAdapterAndMethod()  : bool
Checks whether an adapter or an adapter's method exists
json()  : string
Parses a Response into JSON
jsondata()  : string
Passes JSON data to the particular adapter and returns the result Called from index.php when section is 'jsondata'
loadAdapter()  : mixed
Adds an adapter accessable by JSON requests.
parse()  : string
This method can be used to parse data to JSON format
setSessionId()  : mixed
loadLegacyAdapter()  : mixed

Properties

$adapter_classes

List of adapter class names.

Use component framework instead (SystemComponentController->getControllersAccessableByJson())

protected static array<string|int, mixed> $adapter_classes = array('\Cx\Core\Json\Adapter\User' => array('JsonUser'), '\Cx\Modules\Crm\Controller' => array('JsonCrm'))

List of adapter class names

$adapters

List of adapters to use (they have to implement the JsonAdapter interface)

protected static array<string|int, mixed> $adapters = array()

List of JsonAdapters

$sessionId

Session id for request which we got from the login request

protected string $sessionId = null

Methods

addAdapter()

public static addAdapter(mixed $className[, mixed $namespace = '\' ]) : mixed

Use component framework instead (SystemComponentController->getControllersAccessableByJson())

Parameters
$className : mixed
$namespace : mixed = '\'

data()

Passes JSON data to the particular adapter and returns the result Called from jsondata() or any part of Cloudrexx

public data(string $adapter, string $method[, array<string|int, mixed> $arguments = array() ]) : array<string|int, mixed>
Parameters
$adapter : string

Adapter name

$method : string

Method name

$arguments : array<string|int, mixed> = array()

Arguments to pass, first dimension indexes are "response", "get" (optional) and "post" (optional)

Tags
author

Michael Ritter michael.ritter@comvation.com

Return values
array<string|int, mixed>

Data to use for further processing

getErrorData()

Returns the JSON code for a error message

public getErrorData(string $message) : array<string|int, mixed>
Parameters
$message : string

HTML encoded message

Tags
author

Michael Ritter michael.ritter@comvation.com

Return values
array<string|int, mixed>

Data for JSON response

getJson()

Fetches a json response via HTTP request

public getJson(string $url[, array<string|int, mixed> $data = array() ][, bool $secure = false ][, string $certificateFile = '' ][, array<string|int, mixed> $httpAuth = array() ][, array<string|int, mixed> $files = array() ][, bool $sendJson = false ][, int $timeout = 0 ][, bool $exceptions = false ][, int $retry = 0 ][, int $retryDelay = 1 ]) : stdClass|bool
Parameters
$url : string

URL to get json from

$data : array<string|int, mixed> = array()

(optional) HTTP post data

$secure : bool = false

(optional) Wheter to verify peer using SSL or not, default false

$certificateFile : string = ''

(optional) Local certificate file for non public SSL certificates

$httpAuth : array<string|int, mixed> = array()

Set an optional HTTP Authentication method and supply its login credentials. The supplied array must comply with the following structure:

             $httpAuth = array(
                 'httpAuthMethod'   => 'none|basic|digest|bearer',
                 'httpAuthUsername' => '',
                 'httpAuthPassword' => '',
                 'httpAuthToken' => '',
             );
$files : array<string|int, mixed> = array()

Key is the POST field name, value is the file path

$sendJson : bool = false

Whether to encode data as JSON, default false

$timeout : int = 0

Max. time in seconds the request may take. 0 for no timeout

$exceptions : bool = false

If set to true exceptions are thrown on error (instead of returning false)

$retry : int = 0

Set to a number greater than 0 to automatically retry the request in case no connection can be established to the target host.

$retryDelay : int = 1
Tags
todo

Support cookies (to allow login and similiar features)

Return values
stdClass|bool

Decoded JSON on success, false otherwise

getParser()

Returns the parser used to parse JSON Parser is either a callback function which accepts an instance of \Cx\Core\Routing\Model\Entity\Response as first argument or an object with a parse(\Cx\Core\Routing\Model\Entity\Response $response) method.

public getParser() : object|callable
Return values
object|callable

Parser

hasAdapterAndMethod()

Checks whether an adapter or an adapter's method exists

public hasAdapterAndMethod(string $adapterName[, string $methodName = '' ]) : bool
Parameters
$adapterName : string

Adapter name to check for

$methodName : string = ''

(optional) Method name to check for

Return values
bool

True if adapter or adapter's method exists, false otherwise

json()

Parses a Response into JSON

public json(Response $response[, bool $setHttpHeaders = false ]) : string
Parameters
$response : Response

Data to JSONify

$setHttpHeaders : bool = false

(optional) If true (NOT default) HTTP headers defined by $response will be set.

Return values
string

JSON data to return to client

jsondata()

Passes JSON data to the particular adapter and returns the result Called from index.php when section is 'jsondata'

public jsondata(string $adapter, string $method[, array<string|int, mixed> $arguments = array() ][, bool $setHttpHeaders = true ]) : string
Parameters
$adapter : string

Adapter name

$method : string

Method name

$arguments : array<string|int, mixed> = array()

Arguments to pass, first dimension indexes are "response", "get" (optional) and "post" (optional)

$setHttpHeaders : bool = true

(optional) If true (default) do expose any HTTP header that the calling adapter may set.

Tags
author

Florian Schuetz florian.schuetz@comvation.com

author

Michael Ritter michael.ritter@comvation.com

Return values
string

JSON data to return to client

loadAdapter()

Adds an adapter accessable by JSON requests.

public loadAdapter(string $className[, string $namespace = '' ]) : mixed

Either specify a fully qualified classname, or a classname and the containing namespace separatly

Parameters
$className : string

Fully qualified or class name located in $namespace

$namespace : string = ''

(optional) Namespace for non fully qualified class name

Tags
todo

Adapter loading could be optimized

throws
Exception

if JsonAdapter interface is not implemented or controller can not be found

parse()

This method can be used to parse data to JSON format

public parse(array<string|int, mixed> $data) : string
Parameters
$data : array<string|int, mixed>

Data to be parsed

Return values
string

JSON encoded data

setSessionId()

public setSessionId(mixed $sessionId) : mixed
Parameters
$sessionId : mixed

loadLegacyAdapter()

protected loadLegacyAdapter(mixed $adapter[, mixed $component = null ]) : mixed
Parameters
$adapter : mixed
$component : mixed = null
Tags
deprecated:

This load adapter in a way they shouldn't be loaded


        
On this page

Search results