Skip to content

felipecwb/EventManager

 
 

Repository files navigation

PHPFluent\EventManager

Build Status Code Coverage Code Quality Latest Stable Version Total Downloads License

Installation

Package is available on Packagist, you can install it using Composer.

composer require phpfluent/eventmanager

Usage

Fluent API

$eventManager = new Manager();
$eventManager->updated = function() { // Add listener to the event "updated"
    echo 'Updated' . PHP_EOL;
);
$eventManager->updated(); // Dispatch event "updated"
$eventManager = new Manager();
$eventManager->created = function(array $data) { // Add listener to the event "created"
    echo 'Created ' . json_encode($data) . PHP_EOL;
);
$eventManager->created($user); // Dispatch event "created"

Non-Fluent API

$eventManager = new Manager();

$eventManager->addEventListener(
    "updated",
    function() {
        echo "updated\n";
    }
);

$eventManager->dispatchEvent("updated");
$eventManager = new Manager();

$eventManager->addEventListener(
    "created",
    function(array $data) {
        echo 'Created ' . json_encode($data) . PHP_EOL;
    }
);

$eventManager->dispatchEvent("created", $user);

Predefined Listeners:

  • Callback: uses a callable as listener (default as the sample above).
  • Process: work with Arara\Process to create asynchronous listeners.
  • PThread: uses the pthreads extension as asynchronous listener.

About

An EventManager library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.2%
  • XML 0.8%