22declare(strict_types=1);
31 private static ?
self $globalInstance =
null;
33 public static function global() :
self{
34 return self::$globalInstance ?? (self::$globalInstance =
new self());
38 private array $allLists = [];
43 private array $handlerCaches = [];
51 foreach($this->allLists as $h){
52 $h->unregister($object);
55 foreach($this->allLists as $h){
64 private static function isValidClass(\ReflectionClass $class) : bool{
65 $tags = Utils::parseDocComment((string) $class->getDocComment());
66 return !$class->isAbstract() || isset($tags[
"allowHandle"]);
74 private static function resolveNearestHandleableParent(\ReflectionClass $class) : ?\ReflectionClass{
75 for($parent = $class->getParentClass(); $parent !==
false; $parent = $parent->getParentClass()){
76 if(self::isValidClass($parent)){
95 if(isset($this->allLists[$event])){
96 return $this->allLists[$event];
99 $class = new \ReflectionClass($event);
100 if(!self::isValidClass($class)){
101 throw new \InvalidArgumentException(
"Event must be non-abstract or have the @allowHandle annotation");
104 $parent = self::resolveNearestHandleableParent($class);
105 $cache =
new RegisteredListenerCache();
106 $this->handlerCaches[$event] = $cache;
107 return $this->allLists[$event] =
new HandlerList(
109 parentList: $parent !==
null ? $this->getListFor($parent->getName()) :
null,
120 $cache = $this->handlerCaches[$event] ?? null;
122 return $cache?->list ?? $this->getListFor($event)->getListenerList();
129 return $this->allLists;
getListFor(string $event)
getHandlersFor(string $event)
unregisterAll(RegisteredListener|Plugin|Listener|null $object=null)