Reformatting the EventDispatcher class.

This commit is contained in:
Ilya Bakhlin 2021-12-28 19:50:49 +01:00
parent 336000b8d4
commit c89cd500a1

View file

@ -1,7 +1,14 @@
<?php declare(strict_types=1);
<?php
declare(strict_types = 1);
namespace Chandler\Eventing;
use Chandler\Patterns\TSimpleSingleton;
/**
* @package Chandler\Eventing
*/
class EventDispatcher
{
private $hooks = [];
@ -9,7 +16,6 @@ class EventDispatcher
function addListener($hook): bool
{
$this->hooks[] = $hook;
return true;
}
@ -19,13 +25,10 @@ class EventDispatcher
if ($event instanceof Events\Cancelable)
if ($event->isCancelled())
break;
$method = "on" . str_replace("Event", "", get_class($event));
if (!method_exists($hook, $methodName)) continue;
$hook->$method($event);
}
return $event;
}