state = $state; } /** * @return Memento */ public function saveToMemento() { $state = is_object($this->state) ? clone $this->state : $this->state; return new Memento($state); } public function restoreFromMemento(Memento $memento) { $this->state = $memento->getState(); } }