core/model/modx/rest/modrestclient.class.php
Handles all REST requests and responses
- Package
- modx
- Subpackage
- rest
\modRestClient
The basic REST client for handling REST requests
- Children
- \modRestSockClient
- \modRestCurlClient
- Used_by
- \modTransportProvider
Constants
OPT_RESPONSE_CLASS
= 'restResponse.class'
- Const
- The response class to use when generating the response object
Properties
array
$config= 'array()'
array()
Details- Type
- array
- Access
- public
\modRestClient
$conn= 'null'
null
Details- Type
- \modRestClient
- Access
- public
\modX
$modx= 'null'
null
Details- Type
- \modX
- Access
- public
\modRestResponse
$response= 'null'
null
Details- Type
- \modRestResponse
- Access
- public
Methods
__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.
Name | Type | Description |
---|---|---|
$modx | \modX | &$modx A reference to the modX instance. |
$config | array | An array of configuration options. |
Type | Description |
---|---|
\modRestClient |
getConnection(
)
:
boolean
Get the connection class for the client. Defaults to cURL, then fsockopen. If neither exists, returns false.
Type | Description |
---|---|
boolean | True if a connection can be made. |
- Access
- public
request(
string $host, string $path, string $method
=
'GET', array $params
=
array(), array $options
=
array()
)
:
\modRestResponse
Send a REST request
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. |
Type | Description |
---|---|
\modRestResponse | The response object. |
- Access
- public
setResponseType(
string $type
)
:
void
Sets the response type
Name | Type | Description |
---|---|---|
$type | string | The type to set, either json or xml |
xml2array(
\SimpleXMLElement $obj, array $arr
)
:
boolean
Translates a SimpleXMLElement object into an array.
Name | Type | Description |
---|---|---|
$obj | \SimpleXMLElement | |
$arr | array | &$arr The reference array to store the results in. |
Type | Description |
---|---|
boolean | True if successful. |
- Access
- public
\modRestResponse
A class for handling REST responses
Properties
Methods
__construct(
\modRestClient $client, string $response, string $responseType
=
'xml'
)
:
\modRestResponse
The constructor for the modRestResponse class.
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 |
Type | Description |
---|---|
\modRestResponse |
fromJSON(
)
:
array
Translates current response from JSON to an array
Type | Description |
---|---|
array |
- Access
- public
getError(
)
:
string
Returns an error message, if any.
Type | Description |
---|---|
string | The error message |
- Access
- public
isError(
)
:
boolean
Checks to see whether or not the response is an error response
Type | Description |
---|---|
boolean | True if the response is an error |
- Access
- public
toXml(
)
:
\SimpleXMLElement
Translates the current response object to a SimpleXMLElement instance
Type | Description |
---|---|
\SimpleXMLElement |
- Access
- public