cjEvents by Jo Giraerts <firstname.lastname@example.org>
The base-class is cjEventHandler in event.php. This class implements a singleton observer pattern.
. $handler->singleton($handle_directly): get an instance of this class. The parameter is a boolean which determines if events should be handled immediately after they are raised or if you want to call the handle()-method yourself.
. $handler->attach: Link a callback-function or method to a self-named event.
. $handler->raise : Raise an event. If you set $handle_directly to 'true' when instantiating this object, it will also be handled. This function accepts unlimited amount of parameters which will be given to the callback in 1 array.
. $handler->handle: Handle all the raised events. Calls all the callbacks you defined.
For some examples on how you can use this class, check test_purephp.php.
Just check the test_jquery.html and test_prototype.html for some examples.
. websocket integration
. making the API cleaner to use
. wrapping the JS into it's own namespace and make it load automatically
raisePHPEvent('some event', 'arg1', 'arg2', 'arg3');
The correct callback for this event would be something like this:
$handler = cjEventHandler::singleton();
$handler->attach('some event', 'get_vars_from_js');
echo $params; // 'some event'
echo $params; // 'arg1'
echo $params; // 'arg2'
echo $params; // 'arg3'
echo $params; // '' because it does not exist