Dominik Liebler a6b09d6b18 PHP7 Command
2016-09-22 09:26:25 +02:00

53 lines
888 B
PHP

<?php
namespace DesignPatterns\Behavioral\Command;
/**
* Receiver is specific service with its own contract and can be only concrete.
*/
class Receiver
{
/**
* @var bool
*/
private $enableDate = false;
/**
* @var string[]
*/
private $output = [];
/**
* @param string $str
*/
public function write(string $str)
{
if ($this->enableDate) {
$str .= ' ['.date('Y-m-d').']';
}
$this->output[] = $str;
}
public function getOutput(): string
{
return join("\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;
}
}