41 lines
944 B
PHP
41 lines
944 B
PHP
<?php
|
|
|
|
namespace Kletellier\PdoWrapper;
|
|
|
|
use Evenement\EventEmitter;
|
|
|
|
class EventDispatcher
|
|
{
|
|
private static $instance = null;
|
|
private EventEmitter $emitter;
|
|
|
|
private function __construct()
|
|
{
|
|
$this->emitter = new EventEmitter();
|
|
}
|
|
|
|
private static function getInstance()
|
|
{
|
|
if (self::$instance == null) {
|
|
self::$instance = new EventDispatcher();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
public static function __callStatic($name, $arguments)
|
|
{
|
|
if (count($arguments) == 2) {
|
|
$instance = self::getInstance();
|
|
$event = $arguments[0];
|
|
if ($name == "on") {
|
|
if (is_callable($arguments[1])) {
|
|
$instance->emitter->on($event, $arguments[1]);
|
|
}
|
|
}
|
|
if ($name == "emit") {
|
|
$instance->emitter->emit($event, $arguments);
|
|
}
|
|
}
|
|
}
|
|
}
|