2017 © Pedro Peláez
 

library events

Event Handler For Ice Cream Framework

image

ice-cream/events

Event Handler For Ice Cream Framework

  • Friday, March 16, 2018
  • by AdamKyle
  • Repository
  • 0 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Ice Cream Events

Build Status Packagist Maintenance Made With Love, (*1)

Simple event handler for managing events in Ice Cream., (*2)

Requirements

  • PHP 7.2
  • Is Stand Alone

Documentation

You can view this packages documentation here, (*3)

Usage

Usage is rather simple, first we have to create a listener and register it. A listener is going to listen for new events to be dispatched and then do something when that event is dispatched., (*4)

This is very similar to Symfony's event Dispatcher:, (*5)


// Create the handler: $eventHandler = new EventHandler(); // Create a listener to listen to events being fired: $listener = new Listener();

Lets define the listener class:, (*6)

use IceCreamEvents\Listener;

class PageViewEventListener extends Listener{

  // Read on to see the event definition.
  public function onAction(PageViewEvent $pageViewedEvent) {
     // ... Do something.
  }
}

Now lets create an event:, (*7)

use IceCreamEvents\Event;

class PageViewEvent extends Event {

  protected $pageViewed;

  public function __construct(PageViewed $pageViewed) {
    $this->pageViewed = $pageViewed;
  }

  public function getPageViewed() {
    return $this->pageViewed;
  }
}

Finally lets register the event with the appropriate listener:, (*8)

$eventHandler->register('page.viewed', PageViewEvent::class, PageViewEventListener::class, 'onAction');

Next we dispatch the event:, (*9)

$eventHandler->dispatch('page.viewed');

What this does is register the page viewed event with the listener class and when the event is fired we call the onAction method and pass it the event class. This is similar to how Laravel registers events., (*10)

The Versions

16/03 2018
16/03 2018
21/01 2017

1.1.0

1.1.0.0

Event Handler For Ice Cream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

20/01 2017

1.0

1.0.0.0

Event Handler For Ice Cream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires