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,23 +16,19 @@ class EventDispatcher
function addListener($hook): bool
{
$this->hooks[] = $hook;
return true;
}
function pushEvent(Events\Event $event): Events\Event
{
foreach($hooks as $hook) {
if($event instanceof Events\Cancelable)
if($event->isCancelled())
foreach ($hooks as $hook) {
if ($event instanceof Events\Cancelable)
if ($event->isCancelled())
break;
$method = "on" . str_replace("Event", "", get_class($event));
if(!method_exists($hook, $methodName)) continue;
if (!method_exists($hook, $methodName)) continue;
$hook->$method($event);
}
return $event;
}