mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-05 06:27:25 +02:00
adding the missing classes to show the real purpose of the pattern
This commit is contained in:
30
Command/HelloCommand.php
Normal file
30
Command/HelloCommand.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Command;
|
||||
|
||||
/**
|
||||
* This concrete command calls "print" on the Receiver, but an external
|
||||
* invoker just know he can call "execute"
|
||||
*/
|
||||
class HelloCommand implements Command
|
||||
{
|
||||
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* Each concrete command is builded with different receivers.
|
||||
* Can be one, many, none or even other Command in parameters
|
||||
*/
|
||||
public function __construct(Receiver $console)
|
||||
{
|
||||
$this->output = $console;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
// sometimes, there is no receiver and this is the command which
|
||||
// does all the work
|
||||
$this->output->write('Hello World');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user