mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-07 00:23:25 +02:00
47 lines
851 B
PHP
47 lines
851 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Command;
|
|
|
|
/**
|
|
* Receiver is a specific service with its own contract and can be only concrete.
|
|
*/
|
|
class Receiver
|
|
{
|
|
private bool $enableDate = false;
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
private array $output = [];
|
|
|
|
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;
|
|
}
|
|
}
|