model/modx/rest/modrestclient.class.php
- package
- modx
- subpackage
- rest
- Classes
- modRestClient
- modRestResponse
Description
Handles all REST requests and responses
\modRestClient
- package
- modx
- subpackage
- rest
- Constants
- OPT_AUTHTYPE
- OPT_PATH
- OPT_PORT
- OPT_RESPONSE_CLASS
- OPT_TIMEOUT
- OPT_USERAGENT
- OPT_USERPWD
- Properties
- $config
- $conn
- $modx
- $response
- $responseType
- Methods
- __construct
- getConnection
- request
- setResponseType
- xml2array
Description
The basic REST client for handling REST requests
Constants
OPT_PATH
OPT_PATH = 'path'
Details
- value
- path
- const
- The path of the request
OPT_PORT
OPT_PORT = 'port'
Details
- value
- port
- const
- The port of the request
OPT_RESPONSE_CLASS
OPT_RESPONSE_CLASS = 'restResponse.class'
Details
- value
- restResponse.class
- const
- The response class to use when generating the response object
OPT_TIMEOUT
OPT_TIMEOUT = 'timeout'
Details
- value
- timeout
- const
- The number of seconds before the request times out
OPT_USERAGENT
OPT_USERAGENT = 'userAgent'
Details
- value
- userAgent
- const
- The user-agent sent in the request
OPT_USERPWD
OPT_USERPWD = 'userpwd'
Details
- value
- userpwd
- const
- The user password to send with the request
OPT_AUTHTYPE
OPT_AUTHTYPE = 'authtype'
Details
- value
- authtype
- const
- The authentication type for the request
Properties
$config
array $config = 'array'
Details
- array
The configuration array. - visibility
- public
- default
- array
- final
- false
- static
- false
- access
- public
$conn
\modRestClient $conn = 'null'
Details
-
\modRestClient
The client connection instance to use. - visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$modx
\modX $modx = 'null'
Details
-
\modX
A reference to the modX instance. - visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$response
\modRestResponse $response = 'null'
Details
-
\modRestResponse
The response object after a request is made. - visibility
- public
- default
- null
- final
- false
- static
- false
- access
- public
$responseType
string $responseType = 'xml'
Details
- string
The expected response type - visibility
- public
- default
- xml
- final
- false
- static
- false
- access
- public
Methods
__construct
__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.
Arguments
- $modx
- \modX
&$modx A reference to the modX instance. - $config
- array
An array of configuration options.
Output
Details
- visibility
- public
- final
- false
- static
- false
getConnection
getConnection(
)
:
boolean
Get the connection class for the client. Defaults to cURL, then fsockopen. If neither exists, returns false.
Output
- boolean
- True if a connection can be made.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
request
request(
string $host, string $path, string $method
=
GET, array $params
=
array, array $options
=
array
)
:
\modRestResponse
Send a REST request
Arguments
- $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.
Output
- \modRestResponse
- The response object.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
setResponseType
setResponseType(
string $type
)
:
Sets the response type
Arguments
- $type
- string
The type to set, either json or xml
Details
- visibility
- public
- final
- false
- static
- false
xml2array
xml2array(
\SimpleXMLElement $obj, array $arr
)
:
boolean
Translates a SimpleXMLElement object into an array.
Arguments
- $obj
- \SimpleXMLElement
- $arr
- array
&$arr The reference array to store the results in.
Output
- boolean
- True if successful.
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
\modRestResponse
- package
- modx
- subpackage
- rest
- Properties
- $responseType
- Methods
- __construct
- fromJSON
- getError
- isError
- toXml
Description
A class for handling REST responses
Properties
$responseType
string $responseType = 'xml'
Details
- string
The type of response format - visibility
- public
- default
- xml
- final
- false
- static
- false
Methods
__construct
__construct(
\modRestClient $client, string $response, string $responseType
=
xml
)
:
\modRestResponse
The constructor for the modRestResponse class.
Arguments
- $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
Output
Details
- visibility
- public
- final
- false
- static
- false
fromJSON
fromJSON(
)
:
array
Translates current response from JSON to an array
Output
- array
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
getError
getError(
)
:
string
Returns an error message, if any.
Output
- string
- The error message
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
isError
isError(
)
:
boolean
Checks to see whether or not the response is an error response
Output
- boolean
- True if the response is an error
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
toXml
toXml(
)
:
\SimpleXMLElement
Translates the current response object to a SimpleXMLElement instance
Output
Details
- visibility
- public
- final
- false
- static
- false
- access
- public