mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-06 05:55:09 +02:00
28 lines
743 B
PHP
28 lines
743 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Command;
|
|
|
|
/**
|
|
* This concrete command calls "print" on the Receiver, but an external
|
|
* invoker just knows that it can call "execute"
|
|
*/
|
|
class HelloCommand implements Command
|
|
{
|
|
/**
|
|
* 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 output "Hello World".
|
|
*/
|
|
public function execute()
|
|
{
|
|
// sometimes, there is no receiver and this is the command which does all the work
|
|
$this->output->write('Hello World');
|
|
}
|
|
}
|