From 6f6e86ee4884f9d77bd9510ae3a3c0056261e0b0 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Sat, 11 May 2013 17:33:47 +0200 Subject: [PATCH] adding the missing classes to show the real purpose of the pattern --- Command/Command.php | 24 +++++------------------- Command/HelloCommand.php | 30 ++++++++++++++++++++++++++++++ Command/Invoker.php | 34 ++++++++++++++++++++++++++++++++++ Command/Receiver.php | 20 ++++++++++++++++++++ 4 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 Command/HelloCommand.php create mode 100644 Command/Invoker.php create mode 100644 Command/Receiver.php diff --git a/Command/Command.php b/Command/Command.php index 60e09ad..17d639e 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -1,6 +1,6 @@ what = (string)$what; - } - - public function execute() - { - echo $this->what; - } -} \ No newline at end of file diff --git a/Command/HelloCommand.php b/Command/HelloCommand.php new file mode 100644 index 0000000..1ba3ecb --- /dev/null +++ b/Command/HelloCommand.php @@ -0,0 +1,30 @@ +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'); + } + +} \ No newline at end of file diff --git a/Command/Invoker.php b/Command/Invoker.php new file mode 100644 index 0000000..75d7a23 --- /dev/null +++ b/Command/Invoker.php @@ -0,0 +1,34 @@ +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(); + } + +} \ No newline at end of file diff --git a/Command/Receiver.php b/Command/Receiver.php new file mode 100644 index 0000000..a9b6516 --- /dev/null +++ b/Command/Receiver.php @@ -0,0 +1,20 @@ +