. */ namespace App\Services\LogSystem; use App\Entity\LogSystem\AbstractLogEntry; use InvalidArgumentException; class EventUndoHelper { public const MODE_UNDO = 'undo'; public const MODE_REVERT = 'revert'; protected const ALLOWED_MODES = [self::MODE_REVERT, self::MODE_UNDO]; protected ?AbstractLogEntry $undone_event; protected string $mode; public function __construct() { $this->undone_event = null; $this->mode = self::MODE_UNDO; } public function setMode(string $mode): void { if (!in_array($mode, self::ALLOWED_MODES, true)) { throw new InvalidArgumentException('Invalid mode passed!'); } $this->mode = $mode; } public function getMode(): string { return $this->mode; } /** * Set which event log is currently undone. * After the flush this message is cleared. */ public function setUndoneEvent(?AbstractLogEntry $undone_event): void { $this->undone_event = $undone_event; } /** * Returns event that is currently undone. */ public function getUndoneEvent(): ?AbstractLogEntry { return $this->undone_event; } /** * Clear the currently the set undone event. */ public function clearUndoneEvent(): void { $this->undone_event = null; } /** * Check if a event is undone. */ public function isUndo(): bool { return $this->undone_event instanceof AbstractLogEntry; } }