mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-25 02:33:36 +02:00
88 - Added undo example for command pattern
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user