Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
webservice_rest_server Class Reference

REST service server implementation. More...

Inheritance diagram for webservice_rest_server:

Public Member Functions

 __construct ($authmethod)
 Contructor.
 
 set_rest_format ()
 Set the request format to.
 

Protected Member Functions

 generate_error ($ex)
 Build the error information matching the REST returned value format (JSON or XML)
 
 parse_request ()
 This method parses the $_POST and $_GET superglobals and looks for the following information: 1/ user authentication - username+password or token (wsusername, wspassword and wstoken parameters) 2/ function name (wsfunction parameter) 3/ function parameters (all other parameters except those above) 4/ text format parameters 5/ return rest format xml/json.
 
 send_error ($ex=null)
 Send the error information to the WS client formatted as XML document.
 
 send_headers ()
 Internal implementation - sending of page headers.
 
 send_response ()
 Send the result of function call to the WS client formatted as XML document.
 

Static Protected Member Functions

static xmlize_result ($returns, $desc)
 Internal implementation - recursive function producing XML markup.
 

Protected Attributes

string $restformat
 return method ('xml' or 'json')
 

Detailed Description

REST service server implementation.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

webservice_rest_server::__construct ( $authmethod)

Contructor.

Parameters
string$authmethodauthentication method of the web service (WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN, ...)
string$restformatFormat of the return values: 'xml' or 'json'

Member Function Documentation

◆ generate_error()

webservice_rest_server::generate_error ( $ex)
protected

Build the error information matching the REST returned value format (JSON or XML)

Parameters
exception$exthe exception we are converting in the server rest format
Return values
stringthe error in the requested REST format

◆ send_error()

webservice_rest_server::send_error ( $ex = null)
protected

Send the error information to the WS client formatted as XML document.

Note: the exception is never passed as null, it only matches the abstract function declaration.

Parameters
exception$exthe exception that we are sending

◆ xmlize_result()

static webservice_rest_server::xmlize_result ( $returns,
$desc )
staticprotected

Internal implementation - recursive function producing XML markup.

Parameters
mixed$returnsthe returned values
external_description$desc
Return values
string

The documentation for this class was generated from the following file: