Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
/ Events Public archive

A lightweight event library for PHP

Notifications You must be signed in to change notification settings

Xesau/Events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Superceded by Xesau/Plugins

Xesau\Events

Events is a lightweight library for event handling and hooks in PHP applications.

Example

/**
 * The event class
 */
class MyEvent
{
    // Uses the Event trait
    use Xesau\Event\Event;
    
    public function getName() {
        return 'my.event.name';
    }
    
    /**
     * Variables can be passed with the event object.
     */
    public $data = 'Not set';
    
    /**
     * It is common practice to specify the data in the constructor, though separate functions can be used as well.
     */
    public function __construct($data) {
        $this->data = $data;
    }
}

// Register listener for my.event.name 
Xesau\Event\EventManager::listen('my.event.name', function($myEvent) {
    echo 'Event my.event.name called, data = ', $myEvent->data;
}

// Call the event.
EventManager::call(new MyEvent('custom data'));
// OUTPUT: Event my.event.name called, data = custom data

About

A lightweight event library for PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published