adding the missing classes to show the real purpose of the pattern

This commit is contained in:
Trismegiste
2013-05-11 17:33:47 +02:00
parent cc93827b8f
commit 6f6e86ee48
4 changed files with 89 additions and 19 deletions

34
Command/Invoker.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Command;
/**
* Invoker is using the command given to it.
* Example : an Application in SF2
*/
class Invoker
{
protected $command;
/**
* In the invoker we find this kind of method for subscribing the command.
* There can be also a stack, a list, a fixed set...
*/
public function setCommand(Command $cmd)
{
$this->command = $cmd;
}
public function run()
{
// here is a key feature of the invoker
// the invoker is the same whatever is the command
$this->command->execute();
}
}