sparq-php/event

Events made simple

1.0.4 2018-10-17 22:16 UTC

This package is auto-updated.

Last update: 2025-02-18 19:43:04 UTC


README

pipeline status Latest Stable Version coverage report Total Downloads License

A simple to use event class. Add events to any class with a few lines of codes.

Installation and Autoloading

The recommended method of installing is via Composer.

Run the following command from your project root:

$ composer require sparq-php/event

Objectives

  • Simple to use events
  • Easy integration with other packages/frameworks
  • Fast and low footprint

Usage

require_once __DIR__ . "/vendor/autoload.php";

use Sparq\Event\EventTrait;

class Foo
{
	use EventTrait;

	public function __construct()
	{
		$this->emit('eventName');
	}

	public function __set($key, $value)
	{
		$this->emit('set', [$key, $value]);
	}
}

$Foo = new Foo();
$Foo->on('eventName', function() {
	// do something
});