harp-orm/event-listeners

Simple event listeners with Closures

dev-master 2014-09-09 08:47 UTC

This package is auto-updated.

Last update: 2024-11-21 20:44:59 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

Simple event listeners with Closures.

Usage

$listeners = new EventListeners();

$listeners->addBefore('save', function ($target) {
    // ...
});

$listeners->addAfter('delete', function ($target) {
    // ...
});

$listeners->dispatchEvent('save', $target);
$listeners->dispatchEvent('delete', $target);

A very simple manager object that holds all the appropriate events, and allows you to dispatch these events later.

EventListenersTrait

This trait gives you the ability to easily add eventlisteners to another object.

class TestConfig {
    use EventListenersTrait;
}

$config = new TestConfig();

$config
    ->addEventBefore('delete', function () {
        // ...
    })
    ->addEventAfter('validate', function () {

    });

// Return the EventListeners object
$config->getEventListeners();

Here are all the methods added by this trait.

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin

Under BSD-3-Clause license, read LICENSE file.