Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/netherphp/ki
An event handler.
https://github.com/netherphp/ki
Last synced: 2 months ago
JSON representation
An event handler.
- Host: GitHub
- URL: https://github.com/netherphp/ki
- Owner: netherphp
- License: bsd-2-clause
- Created: 2014-03-23T18:16:56.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T07:30:20.000Z (6 months ago)
- Last Synced: 2024-09-20T00:50:34.768Z (4 months ago)
- Language: PHP
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Nether Ki
==============[![nether.io](https://img.shields.io/badge/nether-ki-C661D2.svg)](http://nether.io/) [![Code Climate](https://codeclimate.com/github/netherphp/ki/badges/gpa.svg)](https://codeclimate.com/github/netherphp/ki) [![Build Status](https://travis-ci.org/netherphp/ki.svg)](https://travis-ci.org/netherphp/ki) [![Packagist](https://img.shields.io/packagist/v/netherphp/ki.svg)](https://packagist.org/packages/netherphp/ki) [![Packagist](https://img.shields.io/packagist/dt/netherphp/ki.svg)](https://packagist.org/packages/netherphp/ki)
#### Basic Use
An event system handler. Queue callbacks to be executed when needed by other parts of the application. Can be used to trigger actions or filter things. Events are one time use by default, but you can also have them persist for multiple uses. This is not a true async thing like React - these filters will block, so they are safe for inline filtering.
Nether\Ki::Queue(string EventName, callable Callback, bool Persist default false);
Nether\Ki::Queue('my-first-event',function(){
echo 'LOL EVENT LULZ';
return;
});That will queue an event to happen the first time we call it.
Nether\Ki::Flow(string EventName, array Args default null);
Nether\Ki::Flow('my-first-event');
After the first Flow, that event will be removed from the queue and additional flows will not proc it until you requeue it.#### Rigging a Filter Event
To create a filter, you'll probably want to make a persistant event, with one of the few valid uses of pass-by-reference in PHP.
Nether\Ki::Queue('app-hates-at-signs',function(&$input){
if(is_string($input)) $input = str_replace('@','',$input);
},true);Then when you want to filter...
Nether\Ki::Flow('app-hates-at-signs',[&$text]);
And that filter will continue to work for the duration of the app.
Install
-------Use Composer.
"require": { "netherphp/ki":"~1.0.0" }