1 | <?php |
||
2 | namespace Mezon\Service; |
||
3 | |||
4 | /** |
||
5 | * Class ServiceSimpleRequestParams |
||
6 | * |
||
7 | * @package Service |
||
8 | * @subpackage ServiceSimpleRequestParams |
||
9 | * @author Dodonov A.A. |
||
10 | * @version v.1.0 (2019/10/31) |
||
11 | * @copyright Copyright (c) 2019, aeon.org |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * Request params fetcher |
||
16 | */ |
||
17 | class ServiceSimpleRequestParams implements \Mezon\Service\ServiceRequestParamsInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Method returns list of the request's headers |
||
22 | * |
||
23 | * @return array[string] Array of headers |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
24 | */ |
||
25 | protected function getHttpRequestHeaders(): array |
||
26 | { |
||
27 | $headers = getallheaders(); |
||
28 | |||
29 | return $headers === false ? [] : $headers; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Method returns request parameter |
||
34 | * |
||
35 | * @param string $param |
||
36 | * parameter name |
||
37 | * @param mixed $default |
||
38 | * default value |
||
39 | * @return mixed Parameter value |
||
40 | */ |
||
41 | public function getParam($param, $default = false) |
||
42 | { |
||
43 | $headers = $this->getHttpRequestHeaders(); |
||
44 | |||
45 | $return = $default; |
||
46 | |||
47 | if (isset($headers[$param])) { |
||
48 | $return = $headers[$param]; |
||
49 | } elseif (isset($_POST[$param])) { |
||
50 | $return = $_POST[$param]; |
||
51 | } elseif (isset($_GET[$param])) { |
||
52 | $return = $_GET[$param]; |
||
53 | } |
||
54 | |||
55 | return $return; |
||
56 | } |
||
57 | } |
||
58 |