2017 © Pedro Peláez
 

library eventee

Eventee is a minimalistic and powerfull event dispatching library for PHP

image

eventee/eventee

Eventee is a minimalistic and powerfull event dispatching library for PHP

  • Tuesday, April 26, 2016
  • by dkraczkowski
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Eventee build status License

Eventee is a minimalistic and powerfull event dispatching library for PHP., (*1)

TOC

Installation

Make sure you have composer installed (More information here). And your php version is >= PHP 5.5., (*2)

composer require eventee/eventee

Listening to an event

$hub = new \Eventee\EventHub();
$hub->addListener(\Eventee\Event::class, function() {
    echo 'Hello world!';
});

Dispatching an event

$hub = new \Eventee\EventHub();
$hub->addListener(\Eventee\Event::class, function() {
    echo 'Hello world!';
});
// Will echo 'Hello World'.
$hub->dispatch(new \Eventee\Event());

Creating custom event

class OnUserCreated extends Event
{
    private $user;

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

    public function getUser()
    {
        return $this->user;
    }
}

$hub = new \Eventee\EventHub();
$hub->addListener(OnUserCreated::class, function(OnUserCreated $e) {
    echo sprintf('Hello world, %s!', $e->getUser());
});
// Will echo 'Hello World, John!'.
$hub->dispatch(new OnUserCreated('John'));

Stopping event from propagation

$hub = new \Eventee\EventHub();
$hub->addListener(\Eventee\Event::class, function(Event $e) {
    $e->stop();
    echo 'Hello ';
});
$hub->addListener(\Eventee\Event::class, function(Event $e) {
    echo 'World';
});
// Will echo 'Hello '.
$hub->dispatch(new \Eventee\Event());

Checking if listener exists

$hub = new \Eventee\EventHub();
$listener = function(Event $e) {
    echo 'Hello ';
}
$hub->addListener(\Eventee\Event::class, $listener);

// Will echo 'Hello world!'
if ($hub->hasListener(\Eventee\Event::class, $listener) {
    echo 'Hello World!';
}

Removing listener

$hub = new \Eventee\EventHub();
$listener = function(Event $e) {
    echo 'Hello ';
}
$hub->addListener(\Eventee\Event::class, $listener);

$hub->removeListener(\Eventee\Event::class, $listener);

// No output this time.
if ($hub->hasListener(\Eventee\Event::class, $listener) {
    echo 'Hello World!';
}

The Versions

26/04 2016

dev-master

9999999-dev

Eventee is a minimalistic and powerfull event dispatching library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dawid Kraczkowski

event event-dispatcher event-emitter observer

26/04 2016

1.0.0

1.0.0.0

Eventee is a minimalistic and powerfull event dispatching library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dawid Kraczkowski

event event-dispatcher event-emitter observer

26/04 2016

0.1.0

0.1.0.0

Eventee is a minimalistic and powerfull event dispatching library for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Dawid Kraczkowski

event event-dispatcher event-emitter observer