mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-07 07:26:32 +02:00
adding the missing classes to show the real purpose of the pattern
This commit is contained in:
34
Command/Invoker.php
Normal file
34
Command/Invoker.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user