2017 © Pedro Peláez
 

library pesy

Pesy: PHP Event System

image

miguelsaddress/pesy

Pesy: PHP Event System

  • Saturday, March 26, 2016
  • by miguelsaddress
  • Repository
  • 2 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Pesy: PHP Event SYstem

This is an event system that allows you to broadcast events that will be handled by different entities than the emitter., (*1)

Paths

Paths can be unique, such as "myPath:extra:thing" or it can contain a wildcard * to show it handles whatever subevent path such as you will see in the case of another:path:* which will handle all subpaths like another:path:like:this but IT WILL NOT HANDLE paths like another:path, (*2)

Initialization:

Create a Handler's centre. It will be the main holder of the Handlers. Technically, though any EventHandlerList would do..., (*3)

$handlersCentre = HandlersCentre::getWithHandlers(array(
    'TextFileDump' => new TextFileDumpSampleHandler(array("sample:*")),
    'OtherTextFileDump' => new TextFileDumpSampleHandler(array("another:path:*"))
));

Once you have the handlers centre or your list, you can create your emitter, that will emit to the list of handlers registered in the handlers list passed by parameter, (*4)

$eventEmitter = new EventEmitter($handlersCentre->getList());

Now, whereever in your code, you can create an event and broadcast it. If th path of the event is handled by any of the handlers, it will be processed. Otherwise, it will be ignored, (*5)

$e = new TestEvent();
$e->setPath("sample:path");
$e->addData("key1", "value1");
$e->addData("key2", array(1,2,3));
$eventEmitter->broadcast($e);

This will not be handled, since no handler is listening for this path wontBeHandled, (*6)

$e = new TestEvent();
$e->setPath("wontBeHandled");
$e->addData("wontAppear", "in text file");
$eventEmitter->broadcast($e);

As told before, this will be handled by the OtherTextFileDump handler, (*7)

$e = new TestEvent();
$e->setPath("another:path:like:this");
$e->addData("will appear", "in text file");
$eventEmitter->broadcast($e);

Contact

You can contact me at my twitter: @miguelsaddress, (*8)

The Versions

26/03 2016

dev-master

9999999-dev

Pesy: PHP Event System

  Sources   Download

MIT

The Development Requires

by Miguel Angel Moreno

26/03 2016

v1.0

1.0.0.0

Pesy: PHP Event System

  Sources   Download

MIT

The Development Requires

by Miguel Angel Moreno