class AJAX extends IOInterface

The interface for using Andromeda over a web server

Constants

OUTPUT_PLAIN

OUTPUT_JSON

OUTPUT_PRINTR

Properties

static private $instances from  Singleton
protected Input[] $inputs from  IOInterface
protected $outmode from  IOInterface
private $retfuncs from  IOInterface
private $numretfuncs from  IOInterface

Methods

static Singleton
GetInstance()

Get the instance of the singleton

__construct()

Construct the singleton for use.

static IOInterface|null
TryGet()

Constructs and returns a singleton of the appropriate interface type

static bool
isApplicable()

Returns whether or not the interface is in use for this request

static bool
isPrivileged()

No description

void
Initialize()

Called during API construction to initialize the interface, e.g. to gather global arguments

array
GetInputs(Config|null $config)

Retrieves an array of input objects to run

array
subGetInputs(Config|null $config)

Retrieves an array of input objects from the request to run

void
DisallowBatch()

Asserts that only one output was given

string
getAddress()

Returns the address of the user on the interface

string
getUserAgent()

Returns the user agent string on the interface

int
GetDebugLevel()

Returns the debugging level requested by the interface

int
GetMetricsLevel()

Returns the perf metrics level requested by the interface

string|null
GetDBConfigFile()

Returns the path to the DB config file requested by the interface

static int
GetDefaultOutmode()

No description

SetOutputMode(int|null $mode)

Sets the output mode to the given mode or null (none) - NOT USED in "multi-output" mode!

RegisterOutputHandler(OutputHandler $f)

Registers a user output handler function to run after the initial commit

bool
isMultiOutput()

Returns true if the output is using multi-output mode

static string
formatSize(int $size)

Returns the binary-packed version of the given integer size

bool
UserOutput(Output $output)

Tells the interface to run the custom user output functions

WriteOutput(Output $output)

Tells the interface to print its final output

GetInput(array $get, array $files, array $request)

Fetches an input object from the HTTP request

static string
GetRemoteURL(string $url, Input $input, bool $params = true)

Build a remote Andromeda request URL

static array
RemoteRequest(string $url, Input $input)

Send a request to a remote Andromeda API

static string|null
HTTPPost(string $url, array $post)

Helper function to send an HTTP post request

Details

in Singleton at line 21
static Singleton GetInstance()

Get the instance of the singleton

Return Value

Singleton

Exceptions

MissingSingletonException

if not yet constructed

in IOInterface at line 97
__construct()

Construct the singleton for use.

This can be overriden if it requires more arguments

Exceptions

DuplicateSingletonException

if already constructed

in IOInterface at line 36
static IOInterface|null TryGet()

Constructs and returns a singleton of the appropriate interface type

Return Value

IOInterface|null

at line 33
static bool isApplicable()

Returns whether or not the interface is in use for this request

Return Value

bool

at line 39
static bool isPrivileged()

No description

Return Value

bool

in IOInterface at line 50
void Initialize()

Called during API construction to initialize the interface, e.g. to gather global arguments

Return Value

void

in IOInterface at line 59
array GetInputs(Config|null $config)

Retrieves an array of input objects to run

Parameters

Config|null $config

Return Value

array

at line 60
protected array subGetInputs(Config|null $config)

Retrieves an array of input objects from the request to run

Requests can put multiple requests to be run in a single transaction by using the batch paramter as an array

Parameters

Config|null $config

Return Value

array

in IOInterface at line 69
void DisallowBatch()

Asserts that only one output was given

Return Value

void

at line 41
string getAddress()

Returns the address of the user on the interface

Return Value

string

at line 46
string getUserAgent()

Returns the user agent string on the interface

Return Value

string

in IOInterface at line 82
int GetDebugLevel()

Returns the debugging level requested by the interface

Return Value

int

in IOInterface at line 85
int GetMetricsLevel()

Returns the perf metrics level requested by the interface

Return Value

int

in IOInterface at line 88
string|null GetDBConfigFile()

Returns the path to the DB config file requested by the interface

Return Value

string|null

at line 52
static int GetDefaultOutmode()

No description

Return Value

int

in IOInterface at line 100
IOInterface SetOutputMode(int|null $mode)

Sets the output mode to the given mode or null (none) - NOT USED in "multi-output" mode!

Parameters

int|null $mode

Return Value

IOInterface

in IOInterface at line 112
IOInterface RegisterOutputHandler(OutputHandler $f)

Registers a user output handler function to run after the initial commit

Sets the output mode to null if bytes !== null and will cause "multi-output" mode to be used if > 1 functions that return > 0 bytes are defined

Parameters

OutputHandler $f

Return Value

IOInterface

See also

IOInterface::isMultiOutput

in IOInterface at line 135
protected bool isMultiOutput()

Returns true if the output is using multi-output mode

Multi-output mode is used when more than one user output function wants to run. To accomodate this, each section will be prefaced with the number of bytes written. In multi-output mode, the requested global output mode is ignored and the request is always finished with JSON output (also with the # of bytes prefixed)

Return Value

bool

See also

IOInterface::formatSize

in IOInterface at line 142
static protected string formatSize(int $size)

Returns the binary-packed version of the given integer size

unsigned long long (always 64 bit, big-endian byte order)

Parameters

int $size

Return Value

string

at line 137
bool UserOutput(Output $output)

Tells the interface to run the custom user output functions

Parameters

Output $output

Return Value

bool

true if a custom function was run

at line 151
WriteOutput(Output $output)

Tells the interface to print its final output

Parameters

Output $output

at line 99
private Input GetInput(array $get, array $files, array $request)

Fetches an input object from the HTTP request

App and Action must be part of $_GET, everything else can be interchangeably in $_GET or $POST - except 'password' and 'auth' which cannot be in $_GET

Parameters

array $get
array $files
array $request

Return Value

Input

at line 216
static string GetRemoteURL(string $url, Input $input, bool $params = true)

Build a remote Andromeda request URL

Parameters

string $url

the base URL of the API

Input $input

the input object describing the request

bool $params

if true, add all params from the $input to the URL

Return Value

string

the compiled URL string

at line 230
static array RemoteRequest(string $url, Input $input)

Send a request to a remote Andromeda API

Parameters

string $url

the base URL of the API

Input $input

the input describing the request

Return Value

array

the decoded remote response

Exceptions

RemoteInvalidException

if decoding the response fails

at line 247
static string|null HTTPPost(string $url, array $post)

Helper function to send an HTTP post request

Parameters

string $url

the URL of the request

array $post

array of data to place in the POST body

Return Value

string|null

the remote response