*/ private array $bufferedEvents = []; public function beginBuffering(): void { $this->bufferDepth++; } #[\Override] public function dispatch(LibEvent $event): void { if ($this->bufferDepth > 0) { $this->bufferedEvents[] = $event; return; } Event::dispatch($event); } public function flush(): void { if ($this->bufferDepth === 0) { return; } $this->bufferDepth--; if ($this->bufferDepth > 0) { return; } $events = $this->bufferedEvents; $this->bufferedEvents = []; foreach ($events as $event) { Event::dispatch($event); } } public function discard(): void { if ($this->bufferDepth === 0) { return; } $this->bufferDepth--; if ($this->bufferDepth === 0) { $this->bufferedEvents = []; } } }