| 1 | <?php |
||
| 10 | class RequestContext { |
||
| 11 | |||
| 12 | CONST METHOD_GET = 'GET'; |
||
| 13 | |||
| 14 | CONST METHOD_POST = 'POST'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $method = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | protected $data = []; |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $method |
||
| 29 | * @param array $attributes |
||
| 30 | */ |
||
| 31 | 10 | public function __construct($method, array $attributes = []) { |
|
| 32 | 10 | if (!is_string($method)) { |
|
| 33 | throw new \InvalidArgumentException('Parameter "method" should be a string, ' . gettype($method) . ' given.'); |
||
| 34 | } |
||
| 35 | 10 | $method = strtoupper($method); |
|
| 36 | 10 | if (!in_array($method, [self::METHOD_GET, self::METHOD_POST])) { |
|
| 37 | 1 | throw new \InvalidArgumentException('Invalid http method name.'); |
|
| 38 | } |
||
| 39 | 9 | $this->method = $method; |
|
| 40 | 9 | $this->data = $attributes; |
|
| 41 | 9 | } |
|
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | 1 | public function getMethod() { |
|
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $method |
||
| 54 | * @return bool |
||
| 55 | */ |
||
| 56 | 2 | public function isMethod($method) { |
|
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $name |
||
| 63 | * @return bool |
||
| 64 | */ |
||
| 65 | 9 | public function has($name) { |
|
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * @param string $name |
||
| 72 | * @return mixed|null |
||
| 73 | */ |
||
| 74 | 9 | public function get($name) { |
|
| 77 | |||
| 78 | |||
| 79 | /** |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | 2 | public function getData() { |
|
| 85 | |||
| 86 | |||
| 87 | } |