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; + } + +}