sinergi / event
PHP event dispatching library
Installs: 863
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sinergi/event
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4
This package is not auto-updated.
Last update: 2026-02-10 14:34:35 UTC
README
A smart PHP event dispatching library that does not require your listeners to be aware of your subjects.
Requirements
This library uses PHP 5.4+.
Installation
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"
}
}
Usage
Listener example
use Sinergi\Event\ListenerInterface;
class MyListener implements ListenerInterface
{
public function onUpdate(Subject $subject)
{
// do something
}
}
Subject example
class Subject
{
public $dispatcher;
public function update()
{
$this->dispatcher->trigger($this, 'update');
}
}
Add listener to dispatcher
use Sinergi\Event\Dispatcher;
$dispatcher = new Dispatcher();
$dispatcher->add(new MyListener());
Bind it all together
$subject = new Subject();
$subject->dispatcher = $dispatcher;
$subject->update();