model/modx/rest/modrestserver.class.php
- package
- modx
- Classes
- modRestServer
Description
\modRestServer
- package
- modx
- subpackage
- rest
- Constants
- OPT_AUTH
- OPT_AUTH_GET
- OPT_AUTH_PASS_VAR
- OPT_AUTH_USER_VAR
- OPT_ENCODING
- OPT_ERROR_DATA_NODE
- OPT_ERROR_MESSAGE_NODE
- OPT_ERROR_NODE
- OPT_FORMAT
- OPT_PROCESSORS_PATH
- OPT_REALM
- OPT_RENDERERS
- OPT_REQUEST_PATH
- OPT_REQUEST_VAR
- Properties
- $error
- Methods
- __construct
- _err204
- _err400
- _err401
- _err404
- _err405
- _err406
- _err411
- _err500
- array2xml
- authenticate
- computePath
- deny
- encode
- error
- handle
- success
Description
An extendable class for handling REST requests.
Constants
OPT_AUTH
OPT_AUTH = 'authenticate'
Details
- value
- authenticate
OPT_AUTH_GET
OPT_AUTH_GET = 'authenticateGet'
Details
- value
- authenticateGet
OPT_AUTH_USER_VAR
OPT_AUTH_USER_VAR = 'authUserVar'
Details
- value
- authUserVar
OPT_AUTH_PASS_VAR
OPT_AUTH_PASS_VAR = 'authPassVar'
Details
- value
- authPassVar
OPT_ENCODING
OPT_ENCODING = 'encoding'
Details
- value
- encoding
OPT_ERROR_DATA_NODE
OPT_ERROR_DATA_NODE = 'error_data_node'
Details
- value
- error_data_node
OPT_ERROR_NODE
OPT_ERROR_NODE = 'error_node'
Details
- value
- error_node
OPT_ERROR_MESSAGE_NODE
OPT_ERROR_MESSAGE_NODE = 'error_message_node'
Details
- value
- error_message_node
OPT_FORMAT
OPT_FORMAT = 'format'
Details
- value
- format
OPT_PROCESSORS_PATH
OPT_PROCESSORS_PATH = 'processors_path'
Details
- value
- processors_path
OPT_REQUEST_PATH
OPT_REQUEST_PATH = 'request_path'
Details
- value
- request_path
OPT_REQUEST_VAR
OPT_REQUEST_VAR = 'requestVar'
Details
- value
- requestVar
OPT_REALM
OPT_REALM = 'realm'
Details
- value
- realm
OPT_RENDERERS
OPT_RENDERERS = 'renderers'
Details
- value
- renderers
Properties
$error
\$error $error = 'false'
Details
- \$error
The current error message - visibility
- protected
- default
- false
- final
- false
- static
- false
- access
- protected
Methods
__construct
__construct(
\modX $modx, array $config
=
array
)
:
Arguments
- $modx
- \modX
A reference to the modX object - $config
- array
An array of configuration options
Details
- visibility
- public
- final
- false
- static
- false
_err204
_err204(
string $output
)
:
string
Sets HTTP 204 response headers
Arguments
- $output
- string
The outputted response to send
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err400
_err400(
string $output
)
:
string
Sets HTTP 400 response headers
Arguments
- $output
- string
The outputted response to send
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err401
_err401(
)
:
string
Sets HTTP 401 response headers
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err404
_err404(
array $scriptProperties
=
array
)
:
string
Sets HTTP 404 response headers
Arguments
- $scriptProperties
- array
An array of properties
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err405
_err405(
string $allowed
=
GET, HEAD
)
:
string
Sets HTTP 405 response headers
Arguments
- $allowed
- string
A comma-separated list of allowed protocols
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err406
_err406(
string $output
)
:
string
Sets HTTP 406 response headers
Arguments
- $output
- string
The outputted response to send
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err411
_err411(
string $output
)
:
string
Sets HTTP 411 response headers
Arguments
- $output
- string
The outputted response to send
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
_err500
_err500(
string $output
)
:
string
Sets HTTP 500 response headers
Arguments
- $output
- string
The outputted response to send
Output
- string
Details
- visibility
- private
- final
- false
- static
- false
array2xml
array2xml(
array $array, integer $level
=
1
)
:
string
Converts an array to xml
Arguments
- $array
- array
- $level
- integer
Output
- string
Details
- visibility
- protected
- final
- false
- static
- false
- access
- protected
authenticate
authenticate(
)
:
boolean
Handles basic authentication for the server
Output
- boolean
- True if successful.
Details
- visibility
- public
- final
- false
- static
- false
- todo
- Add an optional usergroup check
computePath
computePath(
)
:
string
Computes the path for the REST request
Output
- string
- The absolute path to the processor to load
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
deny
deny(
string $message, array $data
=
array
)
:
string
Deny access and send a 401.
Arguments
- $message
- string
- $data
- array
Output
- string
Details
- visibility
- public
- final
- false
- static
- false
encode
encode(
array|\xPDOObject $data, string $root
)
:
string
Encodes the data to the specified format. Defaults to XML.
Arguments
- $data
- array\xPDOObject
- $root
- string
Output
- string
- The encoded message
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
error
error(
string $message, array|\xPDOObject $data
=
array, string $type
=
404
)
:
string
Handles error messages
Arguments
- $message
- string
An error message - $data
- array\xPDOObject
Any additional data - $type
- string
The type of the error message
Output
- string
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
handle
handle(
)
:
string
Handles the REST request and loads the correct processor. Checks for authentication should it be a type not equal to GET if authenticate is set to true, or always if authenticateGet is set to true.
Output
- string
Details
- visibility
- public
- final
- false
- static
- false
- access
- public
success
success(
array|\xPDOObject $data, string $root
)
:
string
Handles success messages
Arguments
- $data
- array\xPDOObject
The data to pass and encode - $root
- string
Output
- string
- The encoded message
Details
- visibility
- public
- final
- false
- static
- false