pfSense-pkg-RESTAPI

Tools.inc

Table of Contents

Functions

is_assoc_array()  : bool
Checks if a given array is an associative array.
cprint()  : void
Conditionally prints a message to the console. The specified $message will only be printed if $condition is true.
bandwidth_to_bits()  : int
Converts a $bandwidth to bits for it's given $bandwidthtype
http_request()  : bool|string
Makes an HTTP request.
get_classes_from_namespace()  : array<string|int, mixed>
Obtains the classes nested under a specified namespace. This only works for namespaces that match the directory structure (e.g. RESTAPI\Core for /usr/local/pkg/RESTAPI/Core) and only includes classes defined in their own class .inc file with a matching name.
generate_documentation()  : bool
Auto-generates OpenAPI documentation for all Endpoints and their associated Models.

Functions

is_assoc_array()

Checks if a given array is an associative array.

is_assoc_array(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>

The array to check.

Return values
bool

true if the value is an associative array. false if it is an indexed array.

cprint()

Conditionally prints a message to the console. The specified $message will only be printed if $condition is true.

cprint(string $message, bool $condition) : void
Parameters
$message : string

The message to be printed if the $condition is true.

$condition : bool

A true or false condition. If the condition is true, the $message will be printed. Otherwise it will not.

bandwidth_to_bits()

Converts a $bandwidth to bits for it's given $bandwidthtype

bandwidth_to_bits(int $bandwidth, string $scale) : int
Parameters
$bandwidth : int

The amount of bandwidth scaled using $bandwidthtype.

$scale : string

The scale of $bandwidth. Options are: b, Kb, Mb, and Gb.

Tags
throws
ServerError

When $bandwidthtype is not a supported option.

Return values
int

The bandwidth's total number of bits.

http_request()

Makes an HTTP request.

http_request(string $url, string $method[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ][, string $username = '' ][, string $password = '' ][, bool $validate_certs = true ]) : bool|string
Parameters
$url : string

The full URL of the resource to submit the request to.

$method : string

The HTTP method to use to submit the request.

$data : array<string|int, mixed> = []

The data payload to submit to the remote host. Only JSON payloads are supported.

$headers : array<string|int, mixed> = []

The HTTP headers to submit in the request.

$username : string = ''

The username portion for basic authentication (if applicable)

$password : string = ''

The password portion for basic authentication (if applicable)

$validate_certs : bool = true

Enables or disables TLS certificate verification.

Return values
bool|string

The response from the remote host.

get_classes_from_namespace()

Obtains the classes nested under a specified namespace. This only works for namespaces that match the directory structure (e.g. RESTAPI\Core for /usr/local/pkg/RESTAPI/Core) and only includes classes defined in their own class .inc file with a matching name.

get_classes_from_namespace(string $namespace[, bool $shortnames = false ]) : array<string|int, mixed>
Parameters
$namespace : string

The namespace to obtain classes from. This must be the full namespace including leading and trailing slash (\Full\Namespace).

$shortnames : bool = false

Obtain the class shortnames instead of FQNs.

Return values
array<string|int, mixed>

An array containing the class names for each .inc class file.

generate_documentation()

Auto-generates OpenAPI documentation for all Endpoints and their associated Models.

generate_documentation() : bool
Return values
bool

        
On this page

Search results