Kernel (class)
Everything goes through the kernel.
Methods
getInstance() static
- ⤶
kernelSingleton instance of class kernel
Get kernel singleton by calling kernel::getInstance().
Use this when there is no other way of accessing kernel:
from static methods and classes that are not subclasses of
\Core\Controller or \Core\Module.
In controllers and subclasses of \Core\Module you can use $this->kernel.
debug() static
- ⤶
booltrue if debug is set to true in config
emit($parent, $name) static
- ⇒
string $parentParent (class) emiting this signal - ⇒
string $nameName of signal
Emit a signal. Usually you should use \Core\Module::emit() for this.
expand($content, $vars = null) static
- ⇒
string $contentString where to expand variables - ⇒
array $varsKey-value paired array of optional extra variables to expand - ⤶
stringExpanded content
Expand variables in content.
Variables are detected from {variable_name} notation.
Built-in variables:
- path:home
- path:root
- path:config
- path:modules
- path:routes
- path:views
- path:cache
- path:data
- path:tmp
- path:web
- session:username
- session:lang
- url:base
- url:error
- url:login
- url:assets
- server:user,
- server:group
- server:uid
- server:gid
Example
$custom_config_file = kernel::expand('{path:config}/custom_config.yml');
tr($text_id, …) static
- ⇒
string $text_idText identifier to translate - ⤶
stringTranslated text
Translate identifier to text. Optional parameters after text are printed as if using sprintf().
Example
Contents of config/translations.yml:
en:
title:
site: My Site
Code:
/* will echo "My Site" when language is set to english */
echo kernel::tr('title:site');
log($level, $message, …) static
- ⇒
int $levelMessage severity level, see php syslog() - ⇒
string $messageMessage to write - ⤶
stringWill always return the message given
Write to log. Works like php syslog() function except additional tags can be given.
Levels:
- LOG_EMERG: system is unusable
- LOG_ALERT: action must be taken immediately
- LOG_CRIT: critical conditions
- LOG_ERR: error conditions
- LOG_WARNING: warning conditions
- LOG_NOTICE: normal, but significant, condition
- LOG_INFO: informational message
- LOG_DEBUG: debug-level message
Any (string) arguments given after the first two are taken as tags for this message. Tags can be used to sort and filter messages afterwards.
msg($type, $message) static
- ⇒
string $typeMessage type - ⇒
string $messageMessage to write - ⤶
stringWill always return the message given
Add a message to be shown to user on next page load. This is a convenient way to queue messages through session data to be shown on the next page load for current browser session.
These messages are usually rendered in views/messages.html.
Following types, though not restricted to, can be used:
- success
- error
- warning
- info
getConfigValue(…) static
- ⤶
mixedValue of the given key set in config
Get value from configuration or null if value with given key-chain is not found. Give chain of keys as parameters.
Example:
/* returns true or false */
kernel::getConfigValue('setup', 'debug');
/* returns whole setup array */
kernel::getConfigValue('setup');
historyPop($count = 0) static
- ⇒
int $countItems to pop from history before returning value popped - ⤶
stringPopped value
Pop $count items from history and return last one popped.
historyDisable() static
Disable current request from being saved into history (session data).
createTempFile($postfix = null) static
- ⇒
string $postfixAppend this string at the end of the filename - ⤶
stringFilename
Create a temporary file that will be removed when request is finished (in kernel destructor).
url($path = false) static
- ⇒
string $pathAppend this string at the end of the URL - ⤶
stringURL
Create manual URL that is prepended with site assets path.
getCacheInstance() static
- ⤶
mixedCurrent cache instance or null if cache is not available
Get current cache instance. This is most probably an instance of phpfastcache.
yamlRead($file, $ttl = 600) static
- ⇒
string $fileFilename of YAML-file to read - ⇒
int $ttlTTL for caching file contents - ⤶
mixedData read from file or false on errors
Read data from YAML-file.
yamlWrite($file, $data) static
- ⇒
string $fileFilename of YAML-file to be written - ⇒
mixed $dataData to write into YAML-file - ⤶
booltrue on success, false on failure
Write data to YAML-file.
Signals
kernel:log
- ⇒
string $messageMessage logged - ⇒
int $levelsyslog() priority level - ⇒
int $timestampTimestamp from time() - ⇒
string $addressRemote address (from$_SERVER['REMOTE_ADDR']) orconsole - ⇒
int $portServer port to which the connection was made (from$_SERVER['SERVER_PORT']) - ⇒
string $session_idSession ID