core/model/modx/rest/modrestclient.class.php

Show: inherited
Table of Contents

Handles all REST requests and responses

Package
modx  
Subpackage
rest  

\modRestClient

Package: modx\rest

The basic REST client for handling REST requests

Children
\modRestSockClient
\modRestCurlClient
Used_by
\modTransportProvider  

Constants

Constant  OPT_PATH = 'path'

Const
The path of the request  
Constant  OPT_PORT = 'port'

Const
The port of the request  
Constant  OPT_RESPONSE_CLASS = 'restResponse.class'

Const
The response class to use when generating the response object  
Constant  OPT_TIMEOUT = 'timeout'

Const
The number of seconds before the request times out  
Constant  OPT_USERAGENT = 'userAgent'

Const
The user-agent sent in the request  
Constant  OPT_USERPWD = 'userpwd'

Const
The user password to send with the request  
Constant  OPT_AUTHTYPE = 'authtype'

Const
The authentication type for the request  

Properties

Propertypublicarray  $config= 'array()'

The configuration array.
Default valuearray()Details
Type
array
Access
public  
Propertypublic\modRestClient  $conn= 'null'

The client connection instance to use.
Default valuenullDetails
Type
\modRestClient
Access
public  
Propertypublicstring  $host= ''

The current host to connect to

Details
Type
string
Propertypublic\modX  $modx= 'null'

A reference to the modX instance.
Default valuenullDetails
Type
\modX
Access
public  
Propertypublic\modRestResponse  $response= 'null'

The response object after a request is made.
Default valuenullDetails
Type
\modRestResponse
Access
public  
Propertypublicstring  $responseType= ''xml''

The expected response type
Default value'xml'Details
Type
string
Access
public  

Methods

methodpublic__construct( \modX $modx, array $config = array() ) : \modRestClient

The constructor for the modRestClient class. Assigns a modX instance reference and sets up the basic config array.

Parameters
Name Type Description
$modx \modX

&$modx A reference to the modX instance.

$config array

An array of configuration options.

Returns
Type Description
\modRestClient
methodpublicgetConnection( ) : boolean

Get the connection class for the client. Defaults to cURL, then fsockopen. If neither exists, returns false.

Returns
Type Description
boolean True if a connection can be made.
Details
Access
public  
methodpublicrequest( string $host, string $path, string $method = 'GET', array $params = array(), array $options = array() ) : \modRestResponse

Send a REST request

Parameters
Name Type Description
$host string

The host of the REST server.

$path string

The path to request to on the REST server.

$method string

The HTTP method to use for the request. May be GET, PUT or POST.

$params array

An array of parameters to send with the request.

$options array

An array of options to pass to the request.

Returns
Type Description
\modRestResponse The response object.
Details
Access
public  
methodpublicsetResponseType( string $type ) : void

Sets the response type

Parameters
Name Type Description
$type string

The type to set, either json or xml

methodpublicxml2array( \SimpleXMLElement $obj, array $arr ) : boolean

Translates a SimpleXMLElement object into an array.

Parameters
Name Type Description
$obj \SimpleXMLElement
$arr array

&$arr The reference array to store the results in.

Returns
Type Description
boolean True if successful.
Details
Access
public  

\modRestResponse

Package: modx\rest

A class for handling REST responses

Properties

Propertypublicstring  $json= 'null'

Default valuenullDetails
Type
string
Propertypublicstring  $responseType= ''xml''

The type of response format
Default value'xml'Details
Type
string
Propertypublic\SimpleXMLElement  $xml= 'null'

Default valuenullDetails
Type
\SimpleXMLElement

Methods

methodpublic__construct( \modRestClient $client, string $response, string $responseType = 'xml' ) : \modRestResponse

The constructor for the modRestResponse class.

Parameters
Name Type Description
$client \modRestClient

&$client A reference to the modRestClient instance.

$response string

The response from the REST server.

$responseType string

The type of response, either xml or json

Returns
Type Description
\modRestResponse
methodpublicfromJSON( ) : array

Translates current response from JSON to an array

Returns
Type Description
array
Details
Access
public  
methodpublicgetError( ) : string

Returns an error message, if any.

Returns
Type Description
string The error message
Details
Access
public  
methodpublicisError( ) : boolean

Checks to see whether or not the response is an error response

Returns
Type Description
boolean True if the response is an error
Details
Access
public  
methodpublictoXml( ) : \SimpleXMLElement

Translates the current response object to a SimpleXMLElement instance

Returns
Type Description
\SimpleXMLElement
Details
Access
public  
Documentation was generated by DocBlox 0.18.1.