alexanderc/open-fw-eventer

This package is abandoned and no longer maintained. No replacement package was suggested.

Event manager used in OpenFW framework

v1.0.0-RC2 2013-11-15 15:58 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:28:19 UTC


README

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
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