selvinortiz/gossip

Lightweight event broadcasting library for PHP 5.4+

v1.0.0 2016-06-23 17:13 UTC

This package is auto-updated.

Last update: 2024-12-21 20:04:55 UTC


README

Gossip

Build Status Total Downloads Latest Stable Version

Description

Gossip is a tiny event broadcasting library written by Selvin Ortiz

Requirements

Install

composer require selvinortiz/gossip

Test

sh spec.sh

Usage

Event broadcasting is a fancy way of saying that Gossip allows you to register your responders to listen for a specific event and when that event is whispered, it can respond.

use SelvinOrtiz\Gossip\Gossip;

class App
{
	public function init()
	{
		Gossip::instance()->whisper(new Event('app.init'));
	}

	public function end()
	{
		Gossip::instance()->whisper(new Event('app.end', [$this]));
	}

	public function log($message)
	{
		// Log a $message to db or file system
	}
}

// Called when app.init is whisper()ed
Gossip::instance()->listen('app.init', function (Event &$event) {
	// Bootstrap third party code, initialize services, etc.
});

// Called only the first time app.end is whisper()ed
Gossip::instance()->listenOnce('app.end', function (Event &$event, $app) {
	// Close db connections, destroy sessions, etc.
	$app->log('Application is ending...');
});

API

API reference is coming soon...

Contribute

Gossip wants to be friendly to first time contributors. Just follow the steps below and if you have questions along the way, please reach out.

  1. Fork it!
  2. Create your bugfix or feature branch
  3. Commit and push your changes
  4. Submit a pull request

License

Gossip is open source software licensed under the MIT License