2017 © Pedro Peláez
 

library lib-event

Event library of the Ride framework

image

ride/lib-event

Event library of the Ride framework

  • Thursday, September 8, 2016
  • by ride-user
  • Repository
  • 7 Watchers
  • 0 Stars
  • 2,961 Installations
  • PHP
  • 17 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Ride: Event Library

Event library of the PHP Ride framework., (*1)

What's In This Library

EventManager

The EventManager interface is the facade for this event system. You can add and remove event listeners and trigger events from here., (*2)

A generic implementation is provided by the GenericEventManager class., (*3)

Event

When you trigger an event on the EventManager, an Event instance is created and passed to the listeners. The Event class holds the name of the event, potential arguments and gives you the possibility to stop cascading to the following listeners., (*4)

EventListener

An EventListener instance defines the event, the callback and weight of a listener. Listeners with a lower weight, will be invoked before listeners with a higher weight., (*5)

EventLoader

The GenericEventManager has lazy load capabilities through the EventLoader interface., (*6)

This interface's purpose is to start resolving listeners when the event is triggered for the first time., (*7)

Code Sample

Check this code sample to see the possibilities of this library:, (*8)

<?php

use ride\library\event\loader\io\EventListenerIO;
use ride\library\event\loader\GenericEventLoader;
use ride\library\event\GenericEventManager;
use ride\library\event\Event;

$eventManager = new GenericEventManager();

// add some event listeners
$eventManager->addEventListener('event', 'callback'); // provide a name of the event and a callback
$eventManager->addEventListener('event', array('MyClass', 'callback'), 10); // added a weight to influence order
$eventManager->addEventListener('test', 'onEvent');

// trigger an event
$eventManager->triggerEvent('test');
$eventManager->triggerEvent('test', array('var' => 'value'));

// event listener callback
function onEvent(Event $event) {
    echo $event->getName();
    echo $event->getArgument('var');

    $event->setPreventDefault(); // stop the listener cascade after this listener
}

// you can lazy load the events through an EventLoader
class YourEventListenerIO implements EventListenerIO {

    public function readEventListeners() {
        return array(
            'event' => array(
                new EventListener('event', 'callback'),
            );
        );
    }

}

$eventListenerIO = new YourEventListenerIO();
$eventLoader = new GenericEventLoader($eventListenerIO);

// all the events will be read at the first trigger, but only initialized when 
// the actual event is triggered
$eventManager->setEventLoader($eventLoader);

Installation

You can use Composer to install this library., (*9)

composer require ride/lib-event

The Versions

08/09 2016

dev-master

9999999-dev

Event library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

dev-develop

dev-develop

Event library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

1.0.1

1.0.1.0

Event library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

10/08 2016

1.0.0

1.0.0.0

Event library of the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

20/10 2013

0.3.2

0.3.2.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

29/09 2013

0.3.1

0.3.1.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

29/09 2013

0.3.0

0.3.0.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

28/09 2013

0.2.1

0.2.1.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

28/09 2013

0.2.0

0.2.0.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

23/09 2013

0.1.0

0.1.0.0

Event library of the Pallo framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd