selvinortiz / gossip
Lightweight event broadcasting library for PHP 5.4+
v1.0.0
2016-06-23 17:13 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-10-21 19:35:25 UTC
README
Description
Gossip is a tiny event broadcasting library written by Selvin Ortiz
Requirements
- PHP 5.4+
- Composer and selvinortiz/gossip
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.
- Fork it!
- Create your bugfix or feature branch
- Commit and push your changes
- Submit a pull request
License
Gossip is open source software licensed under the MIT License