mirror of
https://github.com/openvk/chandler.git
synced 2025-03-31 21:43:59 +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;
|
namespace Chandler\Eventing;
|
||||||
|
|
||||||
use Chandler\Patterns\TSimpleSingleton;
|
use Chandler\Patterns\TSimpleSingleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Chandler\Eventing
|
||||||
|
*/
|
||||||
class EventDispatcher
|
class EventDispatcher
|
||||||
{
|
{
|
||||||
private $hooks = [];
|
private $hooks = [];
|
||||||
|
|
||||||
function addListener($hook): bool
|
function addListener($hook): bool
|
||||||
{
|
{
|
||||||
$this->hooks[] = $hook;
|
$this->hooks[] = $hook;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushEvent(Events\Event $event): Events\Event
|
function pushEvent(Events\Event $event): Events\Event
|
||||||
{
|
{
|
||||||
foreach($hooks as $hook) {
|
foreach ($hooks as $hook) {
|
||||||
if($event instanceof Events\Cancelable)
|
if ($event instanceof Events\Cancelable)
|
||||||
if($event->isCancelled())
|
if ($event->isCancelled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
$method = "on" . str_replace("Event", "", get_class($event));
|
$method = "on" . str_replace("Event", "", get_class($event));
|
||||||
if(!method_exists($hook, $methodName)) continue;
|
if (!method_exists($hook, $methodName)) continue;
|
||||||
|
|
||||||
$hook->$method($event);
|
$hook->$method($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
use TSimpleSingleton;
|
use TSimpleSingleton;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue