Have any questions? Apex
  • fullslide1

Apex


Services Container

There are various small PHP classes available within the /src/svc/ directory, which allow various important components / libraries of Apex to be statically accessed. For example:

namespace apex;

use apex\app;
use apex\svc\db;
use apex\svc\redis;
use apex\svc\debug;

function some_method()
{

    // Debug
    debug::add(3, fmsg("My test debug line"), __FILE__, __LINE__);

    // Redis set
    redis::hset('mykey', 'some_value');

    // Database
    $names = db::get_column("SELECT name FROM products ORDER BY name");
    foreach ($names as $name) {
        echo "Product: $name\n";
    }

}

In the above example it appears we are accessing the methods statically, but in reality we are not. All three classes were created by and retrieved from the dependency injection container, using the classes defined within the bootstrap configuration file (see below). The small service classes simply relay the calls to the proper PHP classes non-statically, providing for greater simplicity and accessibility, while still utilizing the power and flexibility of dependancy injection.

Services Available

The below table lists all services available within the main Apex platform. Please note, installed packages may offer additional services other than those listed below.

Service Description
db The back-end database (mySQL,PostgreSQL, etc.).
redis The redis connection utilizing the popular php-redis extension.
msg Event dispatcher to send one-way direct or two-way RPC calls to listeners / workers.
view Template engine that parses and displays .tpl files.
debug Debugger which also doubles as the log handler.
log The log handler, only useful if you want to add log entries outside of the debugger.
cache Simply caching handler.
storage File handline and management on remote networks, services such as AWS, etc.
auth Authentication library, checks authenticated sessions, and logs in users.
components Provides easy access to check and load components, and call methods within them via dependancy injection.
date Various date functions, such as adding / subtracting a time interval.
encrypt Allows various forms of encryption / decryption, such as basic, user segregated, and PGP.
forms Provides various methods to facilitate handling HTML forms, including server-side form validation, retrieving values of a date / date interval field, and more.
geoip Allows you to easily GeoIP an IP address.
hashes Various methods to parse and load the hashes which are defined within package configuration. Mainly used for select lists.
images Easily manage databases of images -- upload, add, search, generate thumbnails, etc.
io Various methods allowing for easy manipulation and parsing of files and directories including zip archives.

Bootstrap Configuration Files

The /bootstrap/ directory contains one PHP configuration file for each of the different request types (http, cli, test), and defines the exact PHP classes to load for each service. For example, if you wanted to switch to the monolog log handler, or a different database driver, you would do so within these configuration files. For another example, the emailer service is changed in the test.php script to a different PHP class that instead of sending the e-mail messages via SMTP, it returns them to the unit test for assertion testing.

Please take a look at the existing configuration files to see how they are formatted, but they are quite straight forward. They simply return one associative array, the keys being the interface / class name (key within the container), and the value being an array defining the PHP class to load.