88 - Added undo example for command pattern

This commit is contained in:
Andrew Nester
2016-01-16 17:06:43 +03:00
parent 4904def390
commit dddfdf65fc
5 changed files with 141 additions and 2 deletions

View File

@ -7,11 +7,40 @@ namespace DesignPatterns\Behavioral\Command;
*/
class Receiver
{
private $enableDate = false;
private $output = array();
/**
* @param string $str
*/
public function write($str)
{
echo $str;
if ($this->enableDate) {
$str .= ' ['.date('Y-m-d').']';
}
$this->output[] = $str;
}
public function getOutput()
{
return implode("\n", $this->output);
}
/**
* Enable receiver to display message date.
*/
public function enableDate()
{
$this->enableDate = true;
}
/**
* Disable receiver to display message date.
*/
public function disableDate()
{
$this->enableDate = false;
}
}