} public function undoButton($input) { if (isset($this->commands[$input])) { $this->commands[$input]->undo(); } } public function setCommandForButton($buttonId, $cmd) { $this->commands[$buttonId] = $cmd; } public function __toString() { $str = 'Выберете вариант ниже:' . '<br />'; foreach ($this->commands as $key => $command) { $str = $str . $key . ' - ' . (string) $command . '<br />'; } return $str; } } $control = new RemoteControl(); $control->setCommandForButton('1', new LightsCommand(new Light())); $control->setCommandForButton('2', new TvCommand(new Tv())); $control->setCommandForButton('3', new MusicCommand(new Misic())); $control->setCommandForButton('4', new TeapotCommand(new Teapot())); echo (string) $control; echo '<br />'; echo '<br />'; $control->pushButton('4'); echo '<br />'; $control->undoButton('4');