g4/events

events php library

0.1.0 2015-02-09 11:59 UTC

This package is not auto-updated.

Last update: 2024-10-26 16:33:36 UTC


README

events - php library

Install

Via Composer

composer require g4/events

Usage

// Register event as an anonymous function
\G4\Events\PubSub::on('event_name', function($arg1, $arg2) { echo $arg1; echo $arg2; });

// Register event as a class method
\G4\Events\PubSub::on('event_name', [new \G4\Events\Test(), 'test']);

// Unregister all subscribers
\G4\Events\PubSub::clear();

// Unregister all subscribers based on event name
\G4\Events\PubSub::off('event_name');

// Unregister one single subscriber
\G4\Events\PubSub::off('event_name', [new \G4\Events\Test(), 'test']);

// Get all events and subscribers
\G4\Events\PubSub::getEvents();

// Check if event is registered
\G4\Events\PubSub::has('event_name');

// Check if subscriber is registered
\G4\Events\PubSub::has('event_name', [new \G4\Events\Test(), 'test']);

// Trigger event with arguments
\G4\Events\PubSub::trigger('event_name', [12345, 987]);

// Trigger event without arguments
\G4\Events\PubSub::trigger('event_name');

Development

Install dependencies

$ make install

Run tests

$ make test

License

(The MIT License) see LICENSE file for details...