class CLI extends IOInterface

The interface for using Andromeda via local console

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
private $debug
private $metrics
private $dbconf

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()

Initializes CLI by fetching some global params from $argv

array
GetInputs(Config|null $config)

Retrieves an array of input objects to run

array
subGetInputs(Config|null $config)

No description

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

static 
getKey(string $str)

Strips -- off the given string and returns (or false if not found)

static string|null
getNextValue(array $args, int $i)

Returns the next args value (or null if not found) and increments $i

array
GetBatch(string $file)

Reads an array of Input objects from a batch file

GetInput(array $argv)

Fetches an Input object by reading it from the command line

Details

in Singleton at line 21
static Singleton GetInstance()

Get the instance of the singleton

Return Value

Singleton

Exceptions

MissingSingletonException

if not yet constructed

at line 62
__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 54
static bool isApplicable()

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

Return Value

bool

at line 60
static bool isPrivileged()

No description

Return Value

bool

at line 95
void Initialize()

Initializes CLI by fetching some global params from $argv

Options such as output mode, debug level and DB config file should be fetched here before the actual GetInputs() is run later. These options are global, not specific to a single Input instance

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 155
protected array subGetInputs(Config|null $config)

No description

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 133
string getAddress()

Returns the address of the user on the interface

Return Value

string

at line 138
string getUserAgent()

Returns the user agent string on the interface

Return Value

string

at line 144
int GetDebugLevel()

Returns the debugging level requested by the interface

Return Value

int

at line 147
int GetMetricsLevel()

Returns the perf metrics level requested by the interface

Return Value

int

at line 150
string|null GetDBConfigFile()

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

Return Value

string|null

at line 153
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

in IOInterface at line 148
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 298
WriteOutput(Output $output)

Tells the interface to print its final output

Parameters

Output $output

at line 77
static private getKey(string $str)

Strips -- off the given string and returns (or false if not found)

Parameters

string $str

at line 83
static private string|null getNextValue(array $args, int $i)

Returns the next args value (or null if not found) and increments $i

Parameters

array $args
int $i

Return Value

string|null

at line 207
private array GetBatch(string $file)

Reads an array of Input objects from a batch file

Parameters

string $file

Return Value

array

at line 220
private Input GetInput(array $argv)

Fetches an Input object by reading it from the command line

Parameters

array $argv

Return Value

Input