2017 © Pedro Peláez
 

library event_source

A library to create event sources easily

image

bugadani/event_source

A library to create event sources easily

  • Monday, May 2, 2016
  • by bugadani
  • Repository
  • 2 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

EventSource

EventSource is a simple library for PHP 5.4+ to create event source objects., (*1)

Usage

EventSource trait

When you wish to make one of your classes an event source, simply use the EventSource trait in them and call the initializer method., (*2)

class SomeClass {
    use EventSource\EventSource;

    public function __construct() {
        //initialize defines the events that can be used
        $this->initialize(['fooEvent', 'barEvent']);
    }

    public function someMethod() {
        $this->raise('fooEvent', $someOptionalParameter);
    }
}

You can use the on($eventName, $callback) method to define event handlers which will be notified if the given event is raised., (*3)

$someObject = new SomeClass();
$someObject->on('fooEvent', function($someParameter = null) {
    //do something
});

You can also remove event handlers using the remove($eventName, $callback) method., (*4)

Event class

Alternatively, you have the option to manually create Event objects that are used by EventSource to manage the event handlers. The Event class has the following methods:, (*5)

  • on($callback) - register a new callback to handle the event
  • remove($callback) - removes a previously registered callback
  • raise(optional $parameter) - raises the event

One downside is when using the Event class directly is that raise() is a public method, so any outside code may trigger events., (*6)

Installation

Using Composer

"require": {
    "bugadani/event_source": "1.*"
}

The Versions

02/05 2016

v1.x-dev

1.9999999.9999999.9999999-dev

A library to create event sources easily

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Dániel Buga

03/02 2016

dev-master

9999999-dev

A library to create event sources easily

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Dániel Buga

03/02 2016

1.0

1.0.0.0

A library to create event sources easily

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Dániel Buga