2017 © Pedro Peláez
 

library events

PHP events library

image

phasty/events

PHP events library

  • Wednesday, November 18, 2015
  • by dedestr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7,298 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Events

Package supplies support of event handling on different kind of objects. To use this you just inherite your class from Phasty\Events\Eventable or use Phasty\Events\EventableTrait trait within you class:, (*1)

class SomeCoolClass extends Phasty\Events\Eventable {
} 

$obj = new SomeCoolClass;
$obj->on("hello-event", function($event) {
    echo $event->getData();
});
$obj->trigger("hello-event", "Hello world");

Output:, (*2)

Hellow world!

And more:, (*3)

class Button extends Phasty\Events\Eventable {
    public function __construct() {
        $this->on("click", "sayHello");
        $this->on("click", "sayGoodbye");
    }
    protected function sayHello() {
        echo "Hello!\n";
    }
    protected function sayGoodbye() {
        echo "Bye!\n";
    }
    public function click() {
        $this->trigger("before-click");
        $this->trigger("click");
    }
}

$btn = new Button;
$btn->on("before-click", function () {
    echo "Before click handler\n";
});
$btn->click();
$btn->off("click", "sayHello");
$btn->click();

Output:, (*4)

Before click handler
Hello!
Bye!
Before click handler
Bye!

USAGE

// Listen to some-event
$obj->on("some-event", /* Any PHP callback or method name of $obj class */);
// Listen to any event
$obj->on(null, /* Any PHP callback or method name of $obj class */);
// Forget all events callbacks
$obj->off();
// Forget all callbacks of "some-event" event
$obj->off("some-event");
// Forget exact callback for "some-event"
$obj->off("some-event", /* Any PHP callback or method name of $obj class */);

The Versions

18/11 2015

dev-master

9999999-dev

PHP events library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Cheremnykh

php events

18/11 2015

0.1

0.1.0.0

PHP events library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Cheremnykh

php events