- WIP on picea-asset AND error handling

This commit is contained in:
mcndave committed 2023-10-12 19:07:16 +00:00
1 parent 3ccbf6bfab
commit d5de5e665b
7 files changed
+61 -48

No files matched your search

+6 -6
View File
@@ -4,26 +4,26 @@ namespace Picea;
trait EventTrait
{
protected $_eventTraitMethod = "execute";
protected $eventTraitMethod = "execute";
public array $_eventList = [];
public array $eventTraitList = [];
protected array $_returnList = [];
protected array $eventTraitReturnList = [];
public function eventRegister(object $event) : void
{
$this->_eventList[] = $event;
$this->eventTraitList[] = $event;
}
public function eventFromType(string $type) : array
{
return array_filter($this->_eventList, fn($ev) => $ev instanceof $type);
return array_filter($this->eventTraitList, fn($ev) => $ev instanceof $type);
}
public function eventExecute(string $type, ...$arguments) : void
{
foreach($this->eventFromType($type) as $event) {
$this->_returnList[$event::class][] = call_user_func_array([ $event, $this->_eventTraitMethod ], $arguments);
$this->eventTraitReturnList[$event::class][] = call_user_func_array([ $event, $this->eventTraitMethod ], $arguments);
}
}
}