cjEvents: Handle browser events in PHP

Recommend this page to a friend!
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 589 All time: 5,214 This week: 238Up
Version License PHP version Categories
cjevents 0.0.1GNU Lesser Genera...5.2PHP 5, AJAX
Description Author

This package can be used to handle browser events in PHP.

It can register event handler callback functions that should be handled when certain events are triggered.

The main class takes requests to raise events and dispatch them by calling the registered event handler functions.

A specialized sub-class can decode JSON object parameters passed from JavaScript running on the browser to the event handler.

Picture of Jo Giraerts
Name: Jo Giraerts <contact>
Classes: 3 packages by
Country: Belgium Belgium
Age: ???
All time rank: 8793 in Belgium Belgium
Week rank: 1036 Down7 in Belgium Belgium Down

cjEvents by Jo Giraerts <jo.giraerts@gmail.com>

With this library you can do event-based programming in PHP and Javascript.
The base-class is cjEventHandler in event.php. This class implements a singleton observer pattern.

Primary methods:
.   $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.

The real strength comes when you start mixing it up with JQuery or Prototype. With this package it's easy to send events between PHP and Javascript.
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


1. When sending events from javascript to PHP, the arguments you send along, will all arrive to the callback in 1 array.
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');

    function get_vars_from_js($params)
        echo $params[0]; // 'some event'
        echo $params[1]; // 'arg1'
        echo $params[2]; // 'arg2'
        echo $params[3]; // 'arg3'
        echo $params[4]; // '' because it does not exist
  Files folder image Files  
File Role Description
Plain text file event.php Class Base class
Accessible without login Plain text file events.js Data Javascript functions
Accessible without login Plain text file json2.js Data json js lib
Accessible without login Plain text file mycallbacks.php Aux. example callbacks
Accessible without login Plain text file README Doc. Some info
Accessible without login Plain text file test_jquery.html Data Test JQuery
Accessible without login Plain text file test_prototype.html Data Test prototype
Accessible without login Plain text file test_purephp.php Example Example script
Accessible without login Plain text file transferevents.php Aux. Ajax handler

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:5,214
This week:238Up
For more information send a message to info at phpclasses dot org.