2017 © Pedro Peláez
 

library eventing

A simple event handler.

image

tomwright/eventing

A simple event handler.

  • Wednesday, March 23, 2016
  • by TomWright
  • Repository
  • 1 Watchers
  • 0 Stars
  • 347 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Eventing

Build Status Total Downloads Latest Stable Version Latest Unstable Version License, (*1)

Usage

You need an Event and an EventHandler., (*2)

Let's say we have an event class stored in app/eventing/event/UserWasRegistered.php., (*3)

namespace App\Eventing\Event;

class UserWasRegistered extends \TomWright\Eventing\Event\Event
{
    protected $userId;

    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    public function getUserId()
    {
        return $this->userId;
    }
}

Let's also assume we have an event handler class stored in app/eventing/handler/UserWasRegisteredHandler.php., (*4)

namespace App\Eventing\Handler;

class UserWasRegisteredHandler implements \TomWright\Eventing\Listener\ListenerInterface
{   
    public function handle(\TomWright\Eventing\Event\EventInterface $event)
    {
        echo "User #{$event->getUserId()} has been registered.";
    }
}

Now we need to add an Event Handler/Listener namespace so as the EventBus knows where to look for the handlers., (*5)

$bus = \TomWright\Eventing\EventBus::getInstance();
$bus->addListenerNamespace('\\App\\Eventing\\Handler');

Now whenever we register a new user, all we have to do is the following:, (*6)

$bus = \TomWright\Eventing\EventBus::getInstance();
$event = new \App\Eventing\Event\UserWasRegistered();
$event->setUserId(123);
$bus->dispatch($event);

The Versions

23/03 2016

dev-master

9999999-dev

A simple event handler.

  Sources   Download

The Requires

 

23/03 2016

1.0.0

1.0.0.0

A simple event handler.

  Sources   Download

The Requires