A smart PHP event dispatching library that does not require your listeners to be aware of your subjects.
This library uses PHP 5.4+.
It is recommended that you install the Event library through composer. To do so, add the following lines to your composer.json
file.
{
"require": {
"sinergi/event": "dev-master"
}
}
use Sinergi\Event\ListenerInterface;
class MyListener implements ListenerInterface
{
public function onUpdate(Subject $subject)
{
// do something
}
}
class Subject
{
public $dispatcher;
public function update()
{
$this->dispatcher->trigger($this, 'update');
}
}
use Sinergi\Event\Dispatcher;
$dispatcher = new Dispatcher();
$dispatcher->add(new MyListener());
$subject = new Subject();
$subject->dispatcher = $dispatcher;
$subject->update();