mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-06 22:45:27 +02:00
53 lines
888 B
PHP
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;
|
|
}
|
|
}
|