mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-05 05:24:57 +02:00
39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Command;
|
|
|
|
/**
|
|
* This concrete command tweaks receiver to add current date to messages
|
|
* invoker just knows that it can call "execute"
|
|
*/
|
|
class AddMessageDateCommand implements UndoableCommand
|
|
{
|
|
/**
|
|
* Each concrete command is built with different receivers.
|
|
* There can be one, many or completely no receivers, but there can be other commands in the parameters.
|
|
*/
|
|
public function __construct(private Receiver $output)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Execute and make receiver to enable displaying messages date.
|
|
*/
|
|
public function execute()
|
|
{
|
|
// sometimes, there is no receiver and this is the command which
|
|
// does all the work
|
|
$this->output->enableDate();
|
|
}
|
|
|
|
/**
|
|
* Undo the command and make receiver to disable displaying messages date.
|
|
*/
|
|
public function undo()
|
|
{
|
|
// sometimes, there is no receiver and this is the command which
|
|
// does all the work
|
|
$this->output->disableDate();
|
|
}
|
|
}
|