In this document:
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:
require_once("aps/2/runtime.php");
$logger = \APS\LoggerRegistry::get();
// setting new log file, path relative to your script current directory
$logger->setLogFile("logs/myapplication.log");
...
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');
require_once("aps/2/runtime.php");
...
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.
Warning
Starting from aps-php-runtime-2.0-331, function \APS\Logger::get() is deprecated. Use \APS\LoggerRegistry::get() instead.
APSDatabaseConfigurator class
This object is intended for populating a database from a DB schema.
Constructor:
new \APS\DatabaseConfigurator(<application object>, <database object>)
Methods:
importSchema(<schema>)
<schema> - path to the schema file, either absolute or relative, from the calling module location.
importSchemas(<schemas>)
<schemas> - an array of schema file paths
Example from WordPress:
$dHelper = new \APS\DatabaseConfigurator($this, $this->db);
$dHelper->importSchema('schema.sql');
APSFilesConfigurator class.
FilesConfigurator creates configuration files from templates.
Constructor:
new \APS\FilesConfigurator(<application object>, <website object>)
Methods:
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('wp-config.php.in', $this->website->path.'/'.$this->website->root.'/wp-config.php');
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.