\apexapp

The central app / registry for Apex, controls the container, input arrays, registry, request and response contents, the response variables, redis connection, and all other centralized aspects of the application.

Summary

Methods
Properties
Constants
build_container()
get()
has()
set()
make()
makeset()
call()
check_property_docblock()
check_type()
get_use_declarations()
__construct()
get_instance()
kill_instance()
add_file()
setup_test()
get_tzdata()
get_currency_data()
update_config_var()
verify_2fa()
is_verified()
get_counter()
get_reqtype()
set_reqtype()
reset_reqtype()
set_area()
set_theme()
change_theme()
set_uri()
set_userid()
set_timezone()
set_language()
set_currency()
get_host()
get_port()
get_protocol()
get_method()
get_content_type()
get_uri()
get_uri_segments()
get_uri_original()
get_request_body()
getall_request_vars()
get_area()
get_theme()
get_http_controller()
get_action()
get_userid()
get_recipient()
get_ip()
get_user_agent()
get_timezone()
get_language()
get_currency()
_post()
_get()
_cookie()
_server()
_files()
_header()
_header_line()
_config()
has_post()
has_get()
has_cookie()
has_server()
has_config()
has_header()
getall_post()
getall_get()
getall_cookie()
getall_server()
getall_headers()
getall_files()
getall_config()
clear_post()
clear_get()
clear_cookie()
set_cookie()
set_res_http_status()
set_res_content_type()
set_res_header()
set_res_body()
get_res_status()
get_res_content_type()
get_res_header()
get_res_all_headers()
get_res_body()
echo_response()
add_event()
get_event_queue()
No public properties found
No constants found
get_single_file()
No protected properties found
N/A
get_injection_params()
get_class_name()
initialize()
unpack_request()
get_files()
get_client_info()
$services
$items
$use_declarations
$config
$post
$get
$cookie
$server
$files
$request_body
$protocol
$host
$port
$method
$content_type
$uri
$uri_original
$uri_segments
$uri_locked
$http_headers
$http_headers_keys
$area
$theme
$http_controller
$action
$userid
$recipient
$ip_address
$user_agent
$language
$timezone
$currency
$verified_2fa
$res_status
$res_content_type
$res_http_headers
$res_body
$instance
$reqtype
$reqtype_original
$event_queue
N/A

Properties

$services

$services :

Type

$items

$items :

Type

$use_declarations

$use_declarations :

Type

$config

$config :

The various input arrays, including all $_POST, $_GET, $_COOKIE, and $_SERVER variables, which are sanitized and placed in these private arrays ensuring no outside code can modify their values. Also has the $config array that holds all configuration variables.

Type

$post

$post :

Type

$get

$get :

Type

$cookie

$cookie :

Type

$server

$server :

Type

$files

$files :

Type

$request_body

$request_body :

Type

$protocol

$protocol :

Variables regarding the HTTP request, such as request method, protocol, URI, the IP address, user agent, and others.

Type

$host

$host :

Type

$port

$port :

Type

$method

$method :

Type

$content_type

$content_type :

Type

$uri

$uri :

Type

$uri_original

$uri_original :

Type

$uri_segments

$uri_segments :

Type

$uri_locked

$uri_locked :

Type

$http_headers

$http_headers :

Type

$http_headers_keys

$http_headers_keys :

Type

$area

$area :

Additional variables that contain some request information specific to Apex, such as the area being viewed, HTTP controller used to handle the request, etc.

Type

$theme

$theme :

Type

$http_controller

$http_controller :

Type

$action

$action :

Type

$userid

$userid :

User / location variables, such as the ID# of the authenticated user, the language, timezone and currency to display in, IP address, etc.

Type

$recipient

$recipient :

Type

$ip_address

$ip_address :

Type

$user_agent

$user_agent :

Type

$language

$language :

Type

$timezone

$timezone :

Type

$currency

$currency :

Type

$verified_2fa

$verified_2fa :

Type

$res_status

$res_status :

Response variables, such as HTTP status code, content type, contents, etc.

Type

$res_content_type

$res_content_type :

Type

$res_http_headers

$res_http_headers :

Type

$res_body

$res_body :

Type

$instance

$instance :

Base application variables such as request type, container, services, and the app instance itself.

Type

$reqtype

$reqtype :

Type

$reqtype_original

$reqtype_original :

Type

$event_queue

$event_queue :

Type

Methods

build_container()

build_container(string  $reqtype = 'http')

Build container.

Does the initial build of the container, gets the default services based on request type, and loads the necessary PHP classes.

Parameters

string $reqtype

The type of request (http, cli, test, etc.)

get()

get(string  $name)

Get an item from the container.

Parameters

string $name

The name of the item to retrive.

has()

has(string  $name): boolean

Check if container has item available.

Parameters

string $name

The name of the item to check availablility of.

Returns

boolean —

Whether or not name is available.

set()

set(string  $name,mixed  $value)

Set an item into the container

Parameters

string $name

The name of the item.

mixed $value

The value of the item.

make()

make(string  $name,array  $params = array())

Make a new object with dependency injection.

Parameters

string $name

The class name to create.

array $params

Any additional parameters to use within DI.

makeset()

makeset(string  $class_name,array  $params = array()): mixed

Make and set item into container.

Parameters

string $class_name

The class name of the object to make.

array $params

Optional name based params to use during object creation.

Returns

mixed —

The newly created object.

call()

call(array  $callable,array  $params = array()): mixed

Call specific method within a class.

Parameters

array $callable

First element is class name, second element the method name.

array $params

User-defined params to use during injection.

Returns

mixed —

The response from the called method.

check_property_docblock()

check_property_docblock(string  $comment,string  $class_name)

Check doc comment from property.

Checks for the @inject tag, and if found, injects with the value of the @var tag.

Parameters

string $comment

The dov comment of the properlty.

string $class_name

The class name of the property.

check_type()

check_type(mixed  $value,string  $chk_type): boolean

Check variable type.

Parameters

mixed $value

The value to check.

string $chk_type

The type of variabke ti check variable for.

Returns

boolean —

Whether or not the value is of the specified type.

get_use_declarations()

get_use_declarations(string  $filename)

Get use declarations of PHP class.

Parameters

string $filename

The filename of the class.

__construct()

__construct(string  $reqtype = 'http')

Initialize the application.

initialize the app, create container, check and sanitize inputs, connect to redis, and all around get ready to handle the request.

Parameters

string $reqtype

The type of request, defaults to 'http' but can either be 'cli' or 'test'

get_instance()

get_instance()

Get instance of the application. Used to obtain instance for the dependency container statically within views.

kill_instance()

kill_instance()

Kill instance

add_file()

add_file(\apex\string  $var_name,string  $short_name,string  $filename)

Add single file

Parameters

\apex\string $var_name
string $short_name

The name of the file.

string $filename

The full path to the filename to add.

setup_test()

setup_test(string  $uri,string  $method = 'GET',array  $post = array(),array  $get = array(),array  $cookie = array()): string

Setup a test request.

Sets the various necessary variables for a test request, such as URI, request method, POST / GET arrays, and others.

Parameters

string $uri

The URI of the http request

string $method

The method of request (ie. POST or GET). Defaults to GET.

array $post

All POST variables of the request.

array $get

All GET variables of the request.

array $cookie

All COOKIE variables of the request.

Returns

string —

The resulting HTML code of the request.

get_tzdata()

get_tzdata(string  $timezone = ''): array

Gets timezone offset and if is_dst.

Parameters

string $timezone

The ISO timezone to obtain (eg. PST, MST, EST, etc.)

Returns

array —

The number of offset minutes, and a 1/0 if it's DST

get_currency_data()

get_currency_data(string  $currency): array

Get currency formatting info.

Gets formatting info on a given currency, such as the currency sign, number of decimal points, etc.

Parameters

string $currency

The 3 character ISO code of the currency to retrieve.

Returns

array —

An array of info regarding the currency

update_config_var()

update_config_var(string  $var,string  $value)

Update a configuration variable

Parameters

string $var

The variable name within self::$config to update.

string $value

THe value to update the configuration variable to.

verify_2fa()

verify_2fa(array  $vars)

Verify a 2FA request

Parameters

array $vars

The full vars of the 2FA request from redis.

is_verified()

is_verified(): boolean

Check if verified via 2FA

Returns

boolean —

Whether or not the user has been verified via 2FA.

get_counter()

get_counter(string  $counter,integer  $increment = 1): integer

Increment a counter within the redis database

Parameters

string $counter

The name of the counter to increment.

integer $increment

The amount to increment by. Defaults to 1.

Returns

integer —

The value of the counter.

get_reqtype()

get_reqtype(): string

Get the request type

Returns

string —

The request type

set_reqtype()

set_reqtype(string  $reqtype)

Set the request type

Parameters

string $reqtype

The request type to set

reset_reqtype()

reset_reqtype()

Reset request type back to its original.

set_area()

set_area(string  $area)

Set the area

Parameters

string $area

The area to set app to.

set_theme()

set_theme(string  $theme)

Set the theme

Parameters

string $theme

The alias of the theme to set

change_theme()

change_theme(string  $area,string  $theme)

Change the theme of an area.

Parameters

string $area

The alias of the area (eg. admin, members, public)

string $theme

The alias of the theme to change to.

set_uri()

set_uri(string  $uri,boolean  $prepend_area = false,boolean  $lock_uri = false)

`* Set the URI

Sets the URI, which is also used by the template engine to display the correct template. Only use this is you need to change the URI for some reason.

Parameters

string $uri

The URI to set and display next

boolean $prepend_area

Whether or not to prepend the area to the URI. Used for system templates such as 2fa, 500, etc.

boolean $lock_uri

Whether or not to lock the URI from being changed future in the request.

set_userid()

set_userid(integer  $userid)

Set the userid

Parameters

integer $userid

The user ID# to set

set_timezone()

set_timezone(string  $timezone)

Set the session timezone

Parameters

string $timezone

The timezone to set session to

set_language()

set_language(string  $language)

Set the session lanauge

Parameters

string $language

The two character language to set session to

set_currency()

set_currency(string  $currency)

Set the session currency

Parameters

string $currency

The three character ISO currency to set session to

get_host()

get_host(): string

Get the HTTP hostname being requested

Returns

string —

The http host being requested

get_port()

get_port()

Get the port of the HTTP request

get_protocol()

get_protocol(): string

Get HTTP protocol version of request

Returns

string —

The HTTP protocol version

get_method()

get_method()

Get request method of HTTP request

get_content_type()

get_content_type(): string

Get the content type of the request

Returns

string —

Content type of the request

get_uri()

get_uri(): string

Get the full URI being displayed

Returns

string —

The current URI

get_uri_segments()

get_uri_segments(): array

Get URI segments

Returns array of the URI split by the / character with the first segment being left off if a valid HTTP controller. For example, /admin/users/create with leave the /admin/ segment off as it's a HTTP controller, leaving the response as ['users', 'create'].

Returns

array —

The URI segments

get_uri_original()

get_uri_original(): string

Get the original URI of the http request, in case it may have been modified during the processing.

Returns

string —

The original URI

get_request_body()

get_request_body(): string

Get the request body

Returns

string —

The request body

getall_request_vars()

getall_request_vars(): array

Get all request vars in an array instead of one-by-one.

Returns

array —

AN array of all app-specific request vars.

get_area()

get_area(): string

Get the area

Returns

string —

The area

get_theme()

get_theme(): string

Get the current theme.

Returns

string —

The current theme

get_http_controller()

get_http_controller(): string

Get the HTTP controller (ie. middleware) being used for this request.

Returns

string —

The HTTP controller / middleware being used

get_action()

get_action(): string

Get the action / value of 'submit' form field of previous request. Used to identify which form action to perform.

Returns

string —

Value of the 'submit' form field.

get_userid()

get_userid(): integer

Get the current user ID#

Returns

integer —

The user ID

get_recipient()

get_recipient()

Get the recipient. Used for logs, etc.

get_ip()

get_ip(): string

Get the IP address of requesting user

Returns

string —

The user's IP address

get_user_agent()

get_user_agent(): string

Get the user agent of the requestor

Returns

string —

The user agent requesting the page

get_timezone()

get_timezone()

Get the current timezone being used

get_language()

get_language(): string

Get current language being used

Returns

string —

Two character ISO language (en, fr, de, etc.)

get_currency()

get_currency(): string

Get current currency being used

Returns

string —

The currency ISO (USD, GBP, CNY, etc.)

_post()

_post(string  $var): mixed

Get a $_POST variable

Parameters

string $var

The key of the variable to retrive.

Returns

mixed —

The value of the variable, null if not exists.

_get()

_get(string  $var): mixed

Get a $_GET variable

Parameters

string $var

The key of the variable to retrive.

Returns

mixed —

The value of the variable, null if not exists.

_cookie()

_cookie(string  $var): mixed

Get a $_COOKIE variable.

Parameters

string $var

The key of the variable to retrive.

Returns

mixed —

The value of the variable, null if not exists.

_server()

_server(string  $var): mixed

Get a $_SERVER variable

Parameters

string $var

The key of the variable to retrive.

Returns

mixed —

The value of the variable, null if not exists.

_files()

_files(string  $key,\apex\bool  $return_stream = false): array

Get uploaded file

Parameters

string $key

The name of the file

\apex\bool $return_stream

Returns

array —

The filename, mime type, size, and contents of the file.

_header()

_header(string  $key): mixed

Get a http header

Parameters

string $key

The key of the http header to retrive

Returns

mixed —

The value of the variable, null if not exists.

_header_line()

_header_line(string  $key): mixed

Get a http header as single comma delimited line

Parameters

string $key

The key of the http header to retrive

Returns

mixed —

The value of the variable, null if not exists.

_config()

_config(string  $var): mixed

Get a configuration variable from the 'config' hash of redis

Parameters

string $var

The key of the variable to retrive.

Returns

mixed —

The value of the variable, null if not exists.

has_post()

has_post(string  $var): boolean

Check whether or not $_POST variable exists.

Parameters

string $var

The key of the variable to check whether or not it exists.

Returns

boolean —

Whether or not the variable exists.

has_get()

has_get(string  $var): boolean

Check whether or not a $_GET variable exists.

Parameters

string $var

The key of the variable to check whether or not it exists.

Returns

boolean —

Whether or not the variable exists.

has_cookie()

has_cookie(string  $var): boolean

Check whether or not a $_COOKIE variable exists.

Parameters

string $var

The key of the variable to check whether or not it exists.

Returns

boolean —

Whether or not the variable exists.

has_server()

has_server(string  $var): boolean

Check whether or not a $_SERVER variable exists

Parameters

string $var

The key of the variable to check whether or not it exists.

Returns

boolean —

Whether or not the variable exists.

has_config()

has_config(string  $var): boolean

Check whether or not a configuration variable is defined.

Parameters

string $var

The key of the variable to check whether or not it exists.

Returns

boolean —

Whether or not the variable exists.

has_header()

has_header(string  $key): boolean

Check whether or not a http header exists

Parameters

string $key

The key of the http header to check

Returns

boolean —

Whether or not the variable exists.

getall_post()

getall_post()

Get all variables within $_POST

getall_get()

getall_get()

Get all variables within $_GET

getall_cookie()

getall_cookie()

Get all variables within $_COOKIE

getall_server()

getall_server()

Get all variables within $_SERVER

getall_headers()

getall_headers()

Get all http headers

getall_files()

getall_files()

Get all variables within $_FILES

getall_config()

getall_config()

Get all configuration variables

clear_post()

clear_post()

Clear all $_POST variables. Useful to ensure HTML form is not pre-filled.

clear_get()

clear_get()

Clear all $_GET variables. Useful to ensure HTML form is not pre-filled.

clear_cookie()

clear_cookie()

Clear all $_COOKIE variables

set_cookie()

set_cookie(string  $name,string  $value,integer  $expire,string  $path = '/')

Set a new cookie

Parameters

string $name

The name of the cookie.

string $value

The value of the cookie.

integer $expire

Expiration date in seconds.

string $path

The path of the cookie.

set_res_http_status()

set_res_http_status(integer  $code): boolean

Sets the response HTTP status code

Parameters

integer $code

The HTTP status code to give as a response

Returns

boolean —

Whether or not the operation was successful.

set_res_content_type()

set_res_content_type(string  $type): boolean

Sets the content type of the response that will be given. Defaults to 'text/html'.

Parameters

string $type

the content type to set the response to.

Returns

boolean —

Whether or not the operation was successful.

set_res_header()

set_res_header(string  $key,string  $value)

Set a response HTTP header

Parameters

string $key

The name / key of the HTTP header

string $value

The value of the HTTP header

set_res_body()

set_res_body(string  $body)

Set the contents of the response that will be given. Should be used with every request.

Parameters

string $body

The content of the response that will be given.

get_res_status()

get_res_status(): integer

Get the response HTTP sattus

Returns

integer —

The response HTTP status

get_res_content_type()

get_res_content_type(): string

Get response content type.

Returns

string —

The response content-type

get_res_header()

get_res_header(string  $key): string

Get a single response HTTP header

Parameters

string $key

The key of the http header to retrieve.

Returns

string —

The value of the single HTTP response header

get_res_all_headers()

get_res_all_headers(): array

Get list of all response HTTP headers

Returns

array —

Array of all response HTTP headers

get_res_body()

get_res_body(): string

Get the response body contents

Returns

string —

The response body

echo_response()

echo_response()

Outputs the response contents to the user, generally the web browser

add_event()

add_event(string  $action,mixed  $data)

Add event

Used when request is being processed by an event listener. Adds event that will change output of request to queue, which is then passed back to caller for processing.

Parameters

string $action

The action being performed.

mixed $data

Any data necessary for the action.

get_event_queue()

get_event_queue(): array

Get the event queue.

Returns

array —

The event queue.

get_single_file()

get_single_file(\GuzzleHttp\Psr7\UploadedFile  $file,boolean  $return_stream = false): array

Get single file vars

Parameters

\GuzzleHttp\Psr7\UploadedFile $file

The file that was uploaded to retrive vars for.

boolean $return_stream

Whether or not to return a stream, or the full contents of the file. Defaults to false.

Returns

array —

Info on the publoaded file.

get_injection_params()

get_injection_params(\ReflectionMethod  $method,array  $params = array()): mixed

Get injection parameters fr a method.

Parameters

\ReflectionMethod $method

The method to obtain injection parameters for.

array $params

The user defined parameters to use for injection.

Returns

mixed —

Array of parameters if successful, false otherwise (ie. unable to find dependency).

get_class_name()

get_class_name(string  $name): mixed

Get class name

Parameters

string $name

The class name to check, and retrive full class name of.

Returns

mixed —

Either the resulting class name, or flase if not found.

initialize()

initialize()

Private. Conduct base initialization of application.

Complete base initialization of the app, such as loading redis connection info, set error / exception handlers, connect to redis, etc.

unpack_request()

unpack_request()

Private. Unpack the HTTP request.

Unpack the request. Sanitizes the input arrays, checks which controller and URI is being accessed, etc.

get_files()

get_files()

Get all the uploaded files.

Goes through all uploaded files, and places them within the $files property using the UploadedFileInterface interface (via guzzlehttp) as per PSR specifications.

get_client_info()

get_client_info()

Get client information, IP address and user agent