<?php
 abstract class vB_Systemevent_Item implements JsonSerializable { use vB_Trait_NoSerialize; protected array $serializefields = []; public static function restoreFromData(string $data) : ?vB_Systemevent_Item { $dataArray = json_decode($data, true); if ($dataArray === false) { return null; } $class = $dataArray['class']; if (!is_a($class, 'vB_Systemevent_Item', true)) { return null; } $event = new $class(); $event->fromData($dataArray['data']); return $event; } protected function __construct() {} public function interrupt() : bool { return true; } public final function getData() : string { $data = [ 'class' => get_class($this), 'data' => $this, ]; return json_encode($data); } public function jsonSerialize() : mixed { $item = []; foreach ($this->serializefields AS $field) { $item[$field] = $this->{$field}; } return $item; } protected function fromData(mixed $item) : void { foreach ($this->serializefields AS $field) { $this->{$field} = $item[$field]; } } abstract public function run() : void; } 