Table of Contents
Events are one of the most important concept in Atomik. Callback can be registered to listen on any events. When an event is fired (or triggered), all listening callbacks are called.
Atomik provides the listenEvent method.
It takes as first argument an event name and as second a callback.
See http://php.net/callback
for more information on callbacks.
Example 9.1. Listening to an event
function myEventCallback()
{
// ...
}
function myArgEventCallback($arg1, $arg2)
{
// ...
}
Atomik::listenEvent('myEvent', 'myEventCallback');
Atomik::listenEvent('myArgEvent', 'myArgEventCallback');
Events are fired using the fireEvent method
provided by Atomik. It takes as first argument the event name and
optionally as second an array of arguments for callbacks.
Example 9.2. Firing events
Atomik::fireEvent('myEvent');
Atomik::fireEvent('myArgEvent', array('arg1Value', 'arg2Value'));
While events name can be anything you want, Atomik uses a naming convention for its own events.
Events are composed using “Atomik” or a plugin name, followed by the method from which the event was fired and optionnally the event name. Each part is separated using ":" twice and should start with an upper case.
Example 9.3. Example of event naming
The method Atomik::dispatch()
fires an event named “Atomik::Dispatch::Start”.