mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-06 22:45:27 +02:00
35 lines
687 B
PHP
35 lines
687 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Behavioral\Command;
|
|
|
|
/**
|
|
* Invoker is using the command given to it.
|
|
* Example : an Application in SF2.
|
|
*/
|
|
class Invoker
|
|
{
|
|
/**
|
|
* @var CommandInterface
|
|
*/
|
|
private $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 ...
|
|
*
|
|
* @param CommandInterface $cmd
|
|
*/
|
|
public function setCommand(CommandInterface $cmd)
|
|
{
|
|
$this->command = $cmd;
|
|
}
|
|
|
|
/**
|
|
* executes the command; the invoker is the same whatever is the command
|
|
*/
|
|
public function run()
|
|
{
|
|
$this->command->execute();
|
|
}
|
|
}
|