aztech/event-dispatcher

Aztech Event Dispatcher

v1.1.5 2015-02-24 14:12 UTC

This package is auto-updated.

Last update: 2024-04-04 22:07:24 UTC


README

Build status

Build Status Scrutinizer Code Quality Code Coverage HHVM Status

Stability

Latest Stable Version Latest Unstable Version

License

MIT

This library is released under the MIT license. Please see attached LICENSE file.

Installation

Via Composer

Composer is the only supported way of installing aztech/event-dispatcher . Don't know Composer yet ? Read more about it.

$ composer require "aztech/event-dispatcher":"~1"

Autoloading

Add the following code to your bootstrap file :

require_once 'vendor/autoload.php';

Usage

As the name implies, event-dispatcher is a simple event dispatching library. Rather than a long speech, a simple example :

class MyEvent implements \Aztech\Events\Event
{
    function getCategory() {
        return 'my.event';
    }
    
    function getId() {
        return 1;
    }
}

$dispatcher = new \Aztech\Events\EventDispatcher();
$subscriber = new \Aztech\Events\Callback(function (\Aztech\Events\Event $event) {
    echo 'I just received an event : ' . $event->getCategory() . PHP_EOL;
});

$dispatcher->addListener('my.#', $subscriber);
$dispatcher->dispatch(new MyEvent());

Contributing

All contributions are welcome, via issues and pull requests.

When submitting a pull request, please ensure that your changes validate against the test suite and style checkers by running make test. All tests must pass (make must return 0).