Class SloodleResponse

Description

A helper class to validate and structure data for output according to the Sloodle communications specification.

  • usedby: SloodleRequest - Outputs error messages in appropriate format if an error occurs.

Located in /lib/io.php (line 50)


	
			
Variable Summary
Method Summary
 void SloodleResponse ([int $status_code = null], [string $status_descriptor = null], [mixed $data = null])
 void add_data_line (mixed $par)
 void add_side_effect (integer $par)
 void add_side_effects (mixed $par)
 void clear_data ()
 string get_line_separator ()
 void quick_output (int $status_code, [string $status_descriptor = null], [mixed $data = null], [bool $static = true])
 void render_to_string (string &$str)
 void set_avatar_uuid (mixed $par)
 void set_data (mixed $par)
 void set_field_separator (string $sep)
 void set_line_separator (string $sep)
 void set_page_number (mixed $par)
 void set_page_total (mixed $par)
 void set_request_descriptor (mixed $par)
 void set_request_timestamp (mixed $par)
 void set_response_timestamp (mixed $par)
 void set_side_effects (mixed $par)
 void set_status_code (integer $par)
 void set_status_descriptor (mixed $par)
 void set_tracking_code (mixed $par)
 void _internal_validation_error (string $msg)
Variables
string $avatar_uuid = null (line 131)

Avatar UUID.

Should be a string specifying the UUID key of the agent in-world being handled. (Typically of the user who initiated the request). Optional. Ignored if null.

  • access: private
mixed $data = null (line 174)

Data to render following the status line in the response.

This value can either be a scalar (single value, e.g. int, string, float), or an array. If it is a single scalar, it is rendered as a single line. If it is an array, then each element becomes one line. If an element is a scalar, then it is directly output onto the line. If an element is an array, then each child element is output as a separate field on the same line. Optional. Ignored if null.

string $field_separator = "|" (line 66)

The separation string between fields of a response line (by default, a pipe character |).

  • access: private
string $line_separator = "\n" (line 59)

The separation string between lines of the response (typically just a newline).

  • access: private
integer $page_number = null (line 158)

Current page number.

If a response requires multiple pages, this value indicates which page is being returned in this response. Optional, unless $page_total is specified. Ignored if null. Not yet supported.

  • access: private
integer $page_total = null (line 149)

Total number of pages.

If a response requires multiple pages, this value indicates how many pages there are. Optional, unless $page_number is specified. Ignored if null. Not yet supported.

  • access: private
string $request_descriptor = null (line 104)

Request descriptor.

A brief string passed into the request by an LSL script (via HTTP parameter 'sloodlerequestdesc'), which is returned so that it can correctly distinguish one request from anotehr. Optional. Ignored if null.

  • access: private
integer $request_timestamp = null (line 113)

Timestamp when the request was originally made by the LSL script.

This is not filled-in automatically. You must do it manually if you need it. Optional. Ignored if null.

  • access: private
integer $response_timestamp = null (line 122)

Timestamp when the response was generated on the Moodle site.

This is not filled-in automatically. You must do it manually if you need it. Optional. Ignored if null.

  • access: private
mixed $side_effects = null (line 94)

Integer side effect(s) codes.

Status code(s) of side effect(s) incurred during the operation. Can be a single integer, or an array of integers. Optional. Ignored if null.

  • access: private
int $status_code = null (line 75)

Integer status code of the response.

Refer to the status codes page on the Sloodle wiki for a reference. Required.

  • access: private
string $status_descriptor = null (line 84)

Status descriptor string.

Should contain a generalised description/category of the status code. Optional but recommended. Ignored if null.

  • access: private
mixed $tracking_code = null (line 140)

Tracking code of the request.

Use of this value is undefined. Please do not use it. Optional. Ignored if null.

  • access: private
Methods
Constructor SloodleResponse (line 520)

Constructor

  • can intialise some variables

  • access: public
void SloodleResponse ([int $status_code = null], [string $status_descriptor = null], [mixed $data = null])
  • int $status_code: The initial status code for the response (optional - ignore if null)
  • string $status_descriptor: The initial status descriptor for the response (optional - ignore if null)
  • mixed $data: The initial data for the response, which can be a scalar, or a mixed array of scalars/scalar-arrays (see SloodleResponse::$data) (optional - ignore if null)
add_data_line (line 478)

Adds one line of data to the $data member

void add_data_line (mixed $par)
  • mixed $par: A scalar, or an array of scalars
add_side_effect (line 326)

Adds a single side effect code to member $status_code

void add_side_effect (integer $par)
  • integer $par: An integer side-effect code.
add_side_effects (line 285)

Adds one or more integer side effect codes to member $status_code.

void add_side_effects (mixed $par)
  • mixed $par: An integer side effect code, or an array of them.
clear_data (line 504)

Clears all data from member $data

void clear_data ()
get_field_separator (line 214)

Gets the field separator.

  • return: The current field separator string
string get_field_separator ()
get_line_separator (line 194)

Gets the line separator.

  • return: The current line separator string
string get_line_separator ()
quick_output (line 697)

Quick output of data to avoid several accessor calls if the response is very basic.

Can be called statically to allow simple output of basic data. The status code is required, but the other parameters are optional If an error occurs, the LSL-friendly error message is output to the HTTP response, and the script terminated

  • access: public
void quick_output (int $status_code, [string $status_descriptor = null], [mixed $data = null], [bool $static = true])
  • int $status_code: The status code for the response (required)
  • string $status_descriptor: The status descriptor for the response (optional - ignored if null)
  • mixed $data: The data for the response, which can be a scalar, or a mixed array of scalars/scalar-arrays (see SloodleResponse::$data) (optional - ignored if null)
  • bool $static: If true (default), then this function will assume it is being call statically, and construct its own response object. Otherwise, it will all the existing member data to render the output.
render_to_output (line 669)

Outputs the response directly to the HTTP response.

void render_to_output ()
render_to_string (line 537)

Renders the response to a string.

Prior to rendering, this function will perform final validation on all the data. If anything fails, then the script will terminate with an LSL-friendly error message.

void render_to_string (string &$str)
  • string &$str: Reference to a string object which the response should be rendered to.
set_avatar_uuid (line 384)

Accessor function to set member value $avatar_uuid

void set_avatar_uuid (mixed $par)
  • mixed $par: A string containing a UUID, or null to clear it
set_data (line 439)

Accessor function to set member value $data. Note: it is recommended that you use the add_data_line() and clear_data() functions instead of this.

void set_data (mixed $par)
  • mixed $par: Any scalar value, or a mixed array of scalars or scalar arrays, or null to clear it
set_field_separator (line 205)

Sets the field separator.

void set_field_separator (string $sep)
  • string $sep: A string to separate fields
set_line_separator (line 185)

Sets the line separator.

void set_line_separator (string $sep)
  • string $sep: A string to separate lines
set_page_number (line 424)

Accessor function to set member value $page_number

void set_page_number (mixed $par)
  • mixed $par: A positive page number, or null to clear it
set_page_total (line 409)

Accessor function to set member value $page_total

void set_page_total (mixed $par)
  • mixed $par: A positive page total count, or null to clear it
set_request_descriptor (line 339)

Accessor function to set member value $request_descriptor

void set_request_descriptor (mixed $par)
  • mixed $par: A string request descriptor, or null to clear it
set_request_timestamp (line 354)

Accessor function to set member value $request_timestamp

void set_request_timestamp (mixed $par)
  • mixed $par: An integer timestamp, or null to clear it
set_response_timestamp (line 369)

Accessor function to set member value $response_timestamp

void set_response_timestamp (mixed $par)
  • mixed $par: An integer timestamp, or null to clear it
set_side_effects (line 255)

Accessor function to set member value $side_effects. Note: it is recommended that you use add_side_effect() or add_side_effects() instead.

void set_side_effects (mixed $par)
  • mixed $par: An integer side effect code, an array of integer side effect codes, or null to clear it
set_status_code (line 225)

Accessor function to set member value $status_code

void set_status_code (integer $par)
  • integer $par: A non-zero status code
set_status_descriptor (line 240)

Accessor function to set member value $status_descriptor

void set_status_descriptor (mixed $par)
  • mixed $par: A status descriptor string, or null to clear it
set_tracking_code (line 399)

Accessor function to set member value $tracking_code

void set_tracking_code (mixed $par)
  • mixed $par: Any scalar value
_internal_validation_error (line 723)

Internal function to report a data validation error.

Outputs an LSL-friendly error message, and terminates the script

  • access: private
void _internal_validation_error (string $msg)
  • string $msg: The error message to output.

Documentation generated on Mon, 07 Jul 2008 12:32:32 +0100 by phpDocumentor 1.4.0