mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-28 07:19:26 +02:00
38 lines
889 B
PHP
38 lines
889 B
PHP
<?php
|
|
|
|
/*
|
|
* DesignPatternPHP
|
|
*/
|
|
|
|
namespace DesignPatterns\ChainOfResponsibilities\Responsible;
|
|
|
|
use DesignPatterns\ChainOfResponsibilities\Handler;
|
|
use DesignPatterns\ChainOfResponsibilities\Request;
|
|
|
|
class FastStorage extends Handler
|
|
{
|
|
|
|
protected $_data = array();
|
|
|
|
public function __construct($data = array())
|
|
{
|
|
$this->_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;
|
|
}
|
|
|
|
}
|