Functions and Utilities


APS Logger prints messages in default PHP log. On Apache, it is /var/log/httpd/error_log.

To change log location, use the setLogFile method, as follows:


$logger = \APS\LoggerRegistry::get();
// setting new log file, path relative to your script current directory
public function provision() {

APS Logger allows several kinds of log messages, and provides corresponding functions:

  • fatal

  • error

  • info

  • debug

  • trace

The debug and trace log levels are enabled if APS_DEVELOPMENT_MODE is defined. Make sure the APS_DEVELOPMENT_MODE definition is removed, when you release the package into production.

Usage example:

if (!defined('APS_DEVELOPMENT_MODE')) define ('APS_DEVELOPMENT_MODE', 'on');


public function provision() {
   \APS\LoggerRegistry::get()->error("This is error log message");
   \APS\LoggerRegistry::get()->debug("APS Dev mode is on, so this message is printed in log");

Default logger can be replaced with a custom logger using function \APS\LoggerRegistry::set, as follows:

\APS\LoggerRegistry::set(new MyLogger());

Refer to custom logger example.


Starting from aps-php-runtime-2.0-331, function \APS\Logger::get() is deprecated. Use \APS\LoggerRegistry::get() instead.

Shared Apps helpers

The PHP Runtime library provides functions to cover the default needs of shared applications:

  1. Database population.

  2. Configuration files creation.

Databases are populated from schemas (database dumps). Configuration files are created from templates. Before writing the configurations and database, the PHP Runtime replaces placeholders in the configuration templates and schemas with their actual values.

Placeholders have the following format: @@{<name>}@@


@@{db->name}@@ @@{locale}@@ @@{admin_name}@@ @@{admin_email}@@

The <name> part of a placeholder is a property of an application class (the class that extends the ResourceBase class).

Note the use of DocComment blocks in the module, for example:

 * Class Wordpress
 * @type("";)
 * @implements("";)
class Wordpress extends \APS\ResourceBase

The DocComments instruct the PHP Runtime about the meaning of the properties and their connections with the application schema properties and relations.

For example, the definition of a $db object:

 * @link("";)
 * @required
 * @requirement("version >= 5.0")
public $db;

According to this definition, the PHP Runtime pulls database information from an APS Controller, and populates the $db object. WordPress uses the following Database placeholders in the config templates and database schemas:







Website environment definition:

# Webspace information
 * @link("";)
 * @requirement("engines =='php'")
 * @requirement("php.extensions =='mysql', php.safe_mode |= 'yes'")
 * @required
public $website;

WordPress uses the @@{website->urls[0]}@@ placeholder in its DB schema file. It is the first url from the $website->urls[] array.

In addition, there are scalar properties (settings). The PHP Runtime populates them with the values passed by an APS Controller. Settings initially come from application installation wizard forms, filled by the customer.

Here are the WordPress settings:

# Settings
 * @type(string)
 * @title("Administrator Name")
 * @description("Administrator Name")
public $admin_name = "admin";

 * @type(string)
 * @title("Administrator password")
 * @description("Administrator password")
 * @crypt
public $admin_password;

 * @type(string)
 * @title("Administrator email")
 * @format(email)
public $admin_email;

 * @type(string)
 * @title("Blog Name")
public $title;

 * @type(string)
 * @title("Interface language")
 * @option("en-US", "English")
 * @option("da-DK", "Danish")
 * @option("nl-NL", "Dutch")
 * @option("de-DE", "German")
 * @option("fr-FR", "French")
 * @option("it-IT", "Italian")
 * @option("ja-JP", "Japanese")
 * @option("ru-RU", "Russian")
 * @option("pl-PL", "Polish")
 * @option("es-ES", "Spanish")
 * @option("tr-TR", "Turkish")
 * @option("zh-CN", "Chinese Simplified")
 * @option("zh-TW", "Chinese Traditional")
public $locale = "en-US";

Their placeholders in the WordPress schema and configuration files are as follows: @@{admin_name}@@, @@{admin_password}@@, etc.

In addition to the application properties defined in a schema, an application class can contain your own variables. They can also be used as placeholders, but you need to define them before calling the PHP Runtime utilities.

Here are some additional variables from WordPress:

// some security keys
public $auth_key;
public $secure_auth_key;
public $logged_in_key;
public $nonce_key;
public $auth_salt;
public $secure_auth_salt;
public $logged_in_salt;
public $nonce_salt;
public $admin_password_hash;

Have a look at the ‘init’ function where these variables are defined, and other initial actions done - the password encrypted, locale value adjusted according to WordPress needs:

function init() {
       $this->locale = preg_replace("/-/", "_", $this->locale); # WP locale has format en_EN
       $this->admin_password_hash = md5($this->admin_password); # WP password - encrypt md5
       # keys and salts for WP cookies
       $this->auth_key = \APS\generatePassword(64);
       $this->secure_auth_key = \APS\generatePassword(64);
       $this->logged_in_key = \APS\generatePassword(64);
       $this->nonce_key = \APS\generatePassword(64);
       $this->auth_salt = \APS\generatePassword(64);
       $this->secure_auth_salt = \APS\generatePassword(64);
       $this->logged_in_salt = \APS\generatePassword(64);
       $this->nonce_salt = \APS\generatePassword(64);

This init function is called in the begining of each WordPress method, for example, in provision():

public function provision()
   # Executing schema.sql script against $db. Placeholders in schema.sql are replaced with their values
   $dHelper = new \APS\DatabaseConfigurator($this, $this->db);
   # Installing wp config from template. Placeholders in are replaced with their values
   $fSystemHelper = new \APS\FilesConfigurator($this, $this->website);
   $fSystemHelper->writeConfigFile('', $this->website->path.'/'.$this->website->root.'/wp-config.php');

PHP Runtime Utilities

  1. APSDatabaseConfigurator class

    This object is intended for populating a database from a DB schema.


    new \APS\DatabaseConfigurator(<application object>, <database object>)



    <schema> - path to the schema file, either absolute or relative, from the calling module location.


    <schemas> - an array of schema file paths

    Example from WordPress:

    $dHelper = new \APS\DatabaseConfigurator($this, $this->db);
  2. APSFilesConfigurator class.

    FilesConfigurator creates configuration files from templates.


    new \APS\FilesConfigurator(<application object>, <website object>)


    writeConfigFile(<template file path>, <destination file path>)

    <template file path> - full or relative path to the config template.

    <destination file path> - full path to the destination file.

    It reads template file contents, replaces placeholders with values, writes the result to the destination file.

    Example from WordPress:

    $fSystemHelper = new \APS\FilesConfigurator($this, $this->website);
    $fSystemHelper->writeConfigFile('', $this->website->path.'/'.$this->website->root.'/wp-config.php');
  3. Additional functions in the APS namespace.

    In addition, the class provides the following useful functions:

    setWritePermissions(<file path>)

    <file path> - full path to the file for which the write permissions will be set

    setReadonlyPermissions(<file path>)

    <file path> - full path to the file for which the read-only permissions will be set

    function isLinux() {
           return preg_match('/Windows/', $this->environment->Platform->os) ? 0 : 1;
    deleteDirectory(<full directory path>)

    <full directory path> - path to the directory to be deleted.

    $this->auth_key = \APS\generatePassword(64);

    Generates password compatible with the platform password requirements, for example when registering a user in the platform.