Updated - 21/04/2008 - Download - Khaos://:KhEvent - 0.2
Introduction
This library lets you have various events throughout your application for anything you want, some common examples would be events such as user login, logout, authenticate etc.. Once these events are in place you can create observers which are automatically called whenether the event is triggered. This lets you easilly extend your application without having to change your core code as it doesnt need to know any specifics about the observers.
Sample Usage
The best example is probably a user system where you can trigger events for user login, logout, creation, deletion and modification. Observers can then be created utilising these events such as an observer for phpbb allowing you to login, logout, create and delete users from phpbb without having to edit your controller or model files.
Quick Reference
/*
* KhEvent
*
* array trigger ( string $event[, array $args] )
* void register ( string $event, callback $handler )
*/
// Example Trigger
$results = $this->khevent->trigger('onLogin', array('username', 'password'));
// Example Register
$this->khevent->register('onLogin', array(&$this, 'login'));
Pre-Defined Events
onPreController
onPostControllerConstructor
onPostController
onPostSystem
Configuration
KhEvent will work right out the box aslong as the system/cache folder is writable. However if you wish to change the behaviour of KhEvent then create the config file khaos.php.
Below is a sample config which represents the default behaviour of KhCache.
$config['event'] = array(
'directory' => 'observers',
'autoscan' => true
);
everything in the config file is optional so options only need to be specified if you wish to override the default behaviour.
directory - Directory relative to the application path where all the observer files are held (the directory can contain sub folders to aid with organisation)
autoscan - When set to true if you make a change to an observer the observer map cache is automatically updated when set to false you need to manually delete the kh_event_map file in the cache folder if you make a change to the observers directory.