edps/edps

PHP 5.2 port of Événement

Installs: 45

Dependents: 2

Stars: 1

Watches: 1

Forks: 38

Language: PHP

v0.0.2 2012-10-24 14:10 UTC

README

EDPS is a PHP 5.2 port of igorw's Événement.

Build Status

Fetch

The recommended way to install EDPS is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "edps/edps": "dev-master"
    }
}

And run these two commands to install it:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

Now you can add the autoloader, and you will have access to the library:

<?php
require 'vendor/autoload.php';

Usage

Creating an Emitter

<?php
$emitter = new Edps_EventEmitter();

Adding Listeners (>= PHP 5.3)

<?php
$emitter->on('user.create', function (User $user) use ($logger) {
    $logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});

Adding Listeners (< PHP 5.3)

<?php
$emitter->on('user.create', 'onUserCreate');
function onUserCreate(User $user) {
    global $logger;

    $logger->log(sprintf("User '%s' was created.", $user->getLogin()));
}

Emitting Events

<?php
$emitter->emit('user.create', array($user));

Tests

$ phpunit

License

MIT, see LICENSE.