From b581aef8f2d616b6ce6ec3cd5ef2a59e1b91340b Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Sun, 12 May 2013 22:08:35 +0200 Subject: [PATCH] adding concrete handler --- .../Responsible/FastStorage.php | 37 ++++++++++++++++ .../Responsible/SlowStorage.php | 44 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 ChainOfResponsibilities/Responsible/FastStorage.php create mode 100644 ChainOfResponsibilities/Responsible/SlowStorage.php diff --git a/ChainOfResponsibilities/Responsible/FastStorage.php b/ChainOfResponsibilities/Responsible/FastStorage.php new file mode 100644 index 0000000..0011ea0 --- /dev/null +++ b/ChainOfResponsibilities/Responsible/FastStorage.php @@ -0,0 +1,37 @@ +_data = $data; + } + + protected function processing(Request $req) + { + if ('get' === $req->verb) { + if (array_key_exists($req->key, $this->_data)) { + // the handler IS responsible and then processes the request + $req->response = $this->_data[$req->key]; + // instead of returning true, I could return the value but it proves + // to be a bad idea. What if the value IS "false" ? + return true; + } + } + + return false; + } + +} diff --git a/ChainOfResponsibilities/Responsible/SlowStorage.php b/ChainOfResponsibilities/Responsible/SlowStorage.php new file mode 100644 index 0000000..79635bf --- /dev/null +++ b/ChainOfResponsibilities/Responsible/SlowStorage.php @@ -0,0 +1,44 @@ +_data = $data; + } + + protected function processing(Request $req) + { + if ('get' === $req->verb) { + if (array_key_exists($req->key, $this->_data)) { + $req->response = $this->_data[$req->key]; + return true; + } + } + + return false; + } + +}