<?php
 class vB_Shutdown { use vB_Trait_NoSerialize; private static vB_Shutdown $instance; private array $callbacks = []; private bool $called = false; protected function __construct() {} public static function instance() : self { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } public function add(callable $callback) : void { $this->callbacks[] = $callback; } public function shutdown() { if ($this->called) { return; } $session = vB::getCurrentSession(); if (is_object($session)) { $session->save(); } foreach ($this->callbacks AS $callback) { $callback(); } $this->callbacks = []; $this->setCalled(); } public function setCalled() : void { $this->called = true; } } 