Simple event listeners with Closures

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

This package is auto-updated.

Last update: 2024-06-21 19:46:28 UTC


Event Listeners

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

Simple event listeners with Closures.


$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.


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

class TestConfig {
    use EventListenersTrait;

$config = new TestConfig();

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


// Return the EventListeners object

Here are all the methods added by this trait.

Method Description
getEventListeners() Get the EventListeners object
addEventBefore($name, $closure) Add a "before" listener
addEventAfter($name, $closure) Add a "after" listener


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

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