1 | <?php declare(strict_types=1); |
||
2 | |||
3 | /* |
||
4 | * This file is part of indragunawan/rest-service package. |
||
5 | * |
||
6 | * (c) Indra Gunawan <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace IndraGunawan\RestService; |
||
13 | |||
14 | use GuzzleHttp\Command\Result as BaseResult; |
||
15 | |||
16 | class Result extends BaseResult |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $headers; |
||
22 | |||
23 | /** |
||
24 | * @param array $data |
||
25 | * @param array $headers |
||
26 | */ |
||
27 | 3 | public function __construct(array $data = [], array $headers = []) |
|
28 | { |
||
29 | 3 | $this->headers = $headers; |
|
30 | 3 | parent::__construct($data); |
|
31 | 3 | } |
|
32 | |||
33 | /** |
||
34 | * Get all headers of the result. |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | 2 | public function getHeaders() |
|
39 | { |
||
40 | 2 | return $this->headers; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Check if the result has a header by name. |
||
45 | * |
||
46 | * @param string $name |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | 2 | public function hasHeader($name) |
|
51 | { |
||
52 | 2 | return array_key_exists($name, $this->getHeaders()); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get an header of the result by name. |
||
57 | * |
||
58 | * @param string $name |
||
59 | * |
||
60 | * @return mixed|null |
||
61 | */ |
||
62 | 2 | public function getHeader($name) |
|
63 | { |
||
64 | 2 | if ($this->hasHeader($name)) { |
|
65 | 1 | return $this->getHeaders()[$name]; |
|
66 | } |
||
67 | |||
68 | 2 | return; |
|
69 | } |
||
70 | } |
||
71 |