PHP Classes
elePHPant
Icontem

Eventer: Register events and call handlers when they happen

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2013-11-19 (1 year ago) RSS 2.0 feedNot yet rated by the usersTotal: 224 This week: 1All time: 7,312 This week: 1,124Up
Version License PHP version Categories  
eventer 1.0.0GNU General Publi...5.5PHP 5, Language
Description Author  

This package can register events and call handlers when they happen.

It can register several types of events given their names.

It can also register event listener functions that will be called when the events happen.

The event listeners may be called when they match an event by the exact name or by matching a regular expression.

An event listener may be called only the first time it happens or every time.

Picture of AlexanderC
Name: AlexanderC is available for providing paid consulting. Contact AlexanderC .
Classes: 13 packages by
Country: Moldova Moldova
Age: 25
All time rank: 7801 in Moldova Moldova
Week rank: 267 Up1 in Moldova Moldova Equal
Innovation award
Innovation award
Nominee: 3x

Details provided by the author  
OpenFW::Eventer
===============

It is a library used by OpenFW framework.

    Eventer- is an event manager that makes your life easier when using event driven development.
    There are a lot of libraries doing this, but not that beautifully ;)


Advantages
==========

 - No dependencies
 - Easy to use
 - Restful API
 - Latest PHP features usage
 - Well commented
 - ...much more...

Requirements
============
 - PHP 5.5 and higher
 - awesomeness

Installation
============
 - Using composer(through packagist):

        "alexanderc/open-fw-eventer": "dev-master"

 - ... or simply load it using your autoloader (PSR-0 compliant)

Example
=======

```php
<?php
use OpenFW\Events\Eventer;
use OpenFW\Events\Event;
use OpenFW\Events\Matchers\BinaryMatcher;
use OpenFW\Events\Matchers\RegexMatcher;
use OpenFW\Events\Traits\SimplifiedApiTrait;

$eventer = new Eventer();

$events = [
     'foo.bar.event',
     'foo.baz.smth',
     'foo.habra.event',
     'smth.habra.post'
];

foreach($events as $event) {
     $eventer->register($event);
}

echo "Adding some listeners\n";

$eventer->addListener(new BinaryMatcher('foo.habra.event'), function(Event $event) {
     echo sprintf("This will be called on %s event only\n", $event);
});

$eventer->addListener(new RegexMatcher('.+\.habra\..+'), function(Event $event) {
     echo sprintf("Wow, calling habra events! (%s)\n", $event);
});

$eventer->addOnceListener(new RegexMatcher('foo\..+\.event'), function(Event $event) {
     echo sprintf("This event is one of [foo.bar.event, foo.habra.event] -> %s. ", $event),
             "Also this is thrown only once!\n";
});

echo "Trigger all events once using binary matcher\n";
foreach($events as $event) {
     $eventer->trigger($event, ['some', 'data', 'provided', 'to', 'each', 'listener']);
}

echo "Trigger all events that matches against an RegexMatcher\n";
$eventer->triggerUsingMatcher(
             new RegexMatcher('foo\..+\.event'),
             ['some', 'data', 'provided', 'to', 'each', 'listener']
);

// too much words??? check SimplifiedApiTrait...
```

Credentials
===========
OpenFW::Eventer php framework.

Copyright (C) 2013  AlexanderC
  Files folder image Files  
File Role Description
Files folder imagelib (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  lib  
File Role Description
Files folder imageOpenFW (1 directory)

  Files folder image Files  /  lib  /  OpenFW  
File Role Description
Files folder imageEvents (2 files, 2 directories)

  Files folder image Files  /  lib  /  OpenFW  /  Events  
File Role Description
Files folder imageMatchers (3 files)
Files folder imageTraits (1 file)
  Plain text file Event.php Class Class source
  Plain text file Eventer.php Class Main event manager class

  Files folder image Files  /  lib  /  OpenFW  /  Events  /  Matchers  
File Role Description
  Plain text file AbstractMatcher.php Class Class source
  Plain text file BinaryMatcher.php Class Class source
  Plain text file RegexMatcher.php Class Class source

  Files folder image Files  /  lib  /  OpenFW  /  Events  /  Traits  
File Role Description
  Plain text file SimplifiedApiTrait.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%Total:224All time:7,312
 This week:1This week:1,124Up