pfSense-pkg-RESTAPI

Command
in package
uses BaseTraits

Defines an object that executes shell commands and keeps track of the output and result codes.

Table of Contents

Properties

$command  : string
$output  : string
$redirect  : string
$result_code  : int
$trim_whitespace  : bool

Methods

__construct()  : Command
Defines the Command object including the shell command to execute and optional modifiers. Note: By default, the command output will redirect stderr to stdout so error message will be included in the output.
get_class_fqn()  : string
Obtains the fully qualified name of the called class.
get_class_shortname()  : string
Obtains the shortname of the called class.
get_classes_in_namespace()  : array<string|int, mixed>
Obtains all classes associated with this class's current namespace.
log_error()  : void
Logs an error to the syslog.
run_command()  : void
Executes the assigned $command. The $output and $result_code properties will be set after running this method.

Properties

$command

public string $command

The shell command this object should execute.

$output

public string $output = ''

The output of the executed shell command.

$redirect

public string $redirect

An optional shell redirect to append to the end of the $command.

$result_code

public int $result_code = -1

The exit/return code of the executed shell command.

$trim_whitespace

public bool $trim_whitespace = false

Automatically remove excessive whitespace from the command $output.

Methods

__construct()

Defines the Command object including the shell command to execute and optional modifiers. Note: By default, the command output will redirect stderr to stdout so error message will be included in the output.

public __construct(string $command[, bool $trim_whitespace = false ][, string $redirect = '2>&1' ]) : Command
Parameters
$command : string

The shell command to execute.

$trim_whitespace : bool = false

Remove excessive whitespace from the command output.

$redirect : string = '2>&1'

An optional shell redirect to append to the end of the $command.

Return values
Command

Returns this object containing the results of the executed command. Note: the object returned cannot be used to initiate new commands. A new Command object should be created for any additional commands.

get_class_fqn()

Obtains the fully qualified name of the called class.

public get_class_fqn() : string
Return values
string

The FQN for this object's class.

get_class_shortname()

Obtains the shortname of the called class.

public get_class_shortname() : string
Return values
string

The shortname for this object's class.

get_classes_in_namespace()

Obtains all classes associated with this class's current namespace.

public get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
$shortnames : bool = false
Return values
array<string|int, mixed>

An array of classes currently in this object's namespace

log_error()

Logs an error to the syslog.

public static log_error(string $message) : void
Parameters
$message : string

The error message to write to the syslog

run_command()

Executes the assigned $command. The $output and $result_code properties will be set after running this method.

private run_command() : void

        
On this page

Search results