mirror of
https://github.com/openvk/chandler.git
synced 2025-03-29 12:38:12 +03:00
Reformatting the EventDispatcher class.
This commit is contained in:
parent
336000b8d4
commit
c89cd500a1
1 changed files with 15 additions and 12 deletions
|
@ -1,33 +1,36 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Eventing;
|
||||
|
||||
use Chandler\Patterns\TSimpleSingleton;
|
||||
|
||||
/**
|
||||
* @package Chandler\Eventing
|
||||
*/
|
||||
class EventDispatcher
|
||||
{
|
||||
private $hooks = [];
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
use TSimpleSingleton;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue