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'
nullDetails- Type
- \modRestClient
- Access
- public

\modX
$modx= 'null'
nullDetails- Type
- \modX
- Access
- public

\modRestResponse
$response= 'null'
nullDetails- Type
- \modRestResponse
- Access
- public
Methods

__construct(
\modX $modx, array $config
=
array()
)
:
\modRestClientThe 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(
)
:
booleanGet 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()
)
:
\modRestResponseSend 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
)
:
voidSets the response type
| Name | Type | Description |
|---|---|---|
| $type | string | The type to set, either json or xml |

xml2array(
\SimpleXMLElement $obj, array $arr
)
:
booleanTranslates 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'
)
:
\modRestResponseThe 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(
)
:
arrayTranslates current response from JSON to an array
| Type | Description |
|---|---|
| array |
- Access
- public

getError(
)
:
stringReturns an error message, if any.
| Type | Description |
|---|---|
| string | The error message |
- Access
- public

isError(
)
:
booleanChecks to see whether or not the response is an error response
| Type | Description |
|---|---|
| boolean | True if the response is an error |
- Access
- public

toXml(
)
:
\SimpleXMLElementTranslates the current response object to a SimpleXMLElement instance
| Type | Description |
|---|---|
| \SimpleXMLElement |
- Access
- public