Download the PHP package attozk/evenement-plus without Composer
On this page you can find all versions of the php package attozk/evenement-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download attozk/evenement-plus
More information about attozk/evenement-plus
Files in attozk/evenement-plus
Package evenement-plus
Short Description Événement is a very simple event dispatching library for PHP
License MIT
Informations about the package evenement-plus
Événement-Plus
This is a fork of Événement by Igor Wiedler with advanced dispatching options.
Install
The recommended way to install Événement-Plus is through composer.
Just create a composer.json file for your project:
And run these two commands to install it:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
Now you can add the autoloader, and you will have access to the library:
Usage
Included are two types of event emitters:
- EventEmitter - the original from Événement
- EventEmitterRegex - with regex based event dispatching
EventEmitter Usage
Creating an Emitter
Adding Listeners
Emitting Events
EventEmitterRegex Usage
EventEmitterRegex
uses regex to dispatching events.
Creating an Emitter
Adding Listeners
Addint multiple listeners using an array:
Above is the same as adding one listener at a time:
Adding regex listeners:
The following listeners would match request.www.domain.\w+
and request.example.(com|pk)
patterns
Emitting Events
Emitting Events First Match Win
Emitting Events With Default Fallback-Callback
For cases when you want to perform a default action when there are no listeners:
Benchmarking
There is no doubt regex matching would be slower as the number of listeners goes up.
Following shows benchmarks for various scenarios.
Fixed number of listeners and variable emits
Same number of listeners and emits
Tests
$ phpunit
License
MIT, see LICENSE.