1 | <?php |
||
16 | trait HttpTrait |
||
17 | { |
||
18 | /** |
||
19 | * Initial state of some variables |
||
20 | * |
||
21 | * @var \GuzzleHttp\Client |
||
22 | */ |
||
23 | private $client; |
||
24 | |||
25 | /** |
||
26 | * Object of main config |
||
27 | * |
||
28 | * @var \PiHole\Config |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * Request executor with timeout and repeat tries |
||
34 | * |
||
35 | * @param string $type Request method |
||
36 | * @param array $params List of parameters |
||
37 | * @param array|null $endpoint endpoint url |
||
38 | * @param bool $auth |
||
39 | * |
||
40 | * @return null|\Psr\Http\Message\ResponseInterface |
||
41 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
42 | * @throws \ErrorException |
||
43 | */ |
||
44 | private function repeatRequest(string $type, array $endpoint = null, array $params = null, bool $auth = false): ?ResponseInterface |
||
79 | |||
80 | /** |
||
81 | * Execute request and return response |
||
82 | * |
||
83 | * @return null|object Array with data or NULL if error |
||
84 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
85 | * @throws \ErrorException |
||
86 | * @throws \PiHole\Exceptions\EmptyResults |
||
87 | */ |
||
88 | public function exec() |
||
92 | |||
93 | /** |
||
94 | * Execute query and return RAW response from remote API |
||
95 | * |
||
96 | * @return null|\Psr\Http\Message\ResponseInterface RAW response or NULL if error |
||
97 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
98 | * @throws \ErrorException |
||
99 | * @throws \PiHole\Exceptions\EmptyResults |
||
100 | */ |
||
101 | public function raw(): ?ResponseInterface |
||
105 | |||
106 | /** |
||
107 | * Make the request and analyze the result |
||
108 | * |
||
109 | * @param string $type Request method |
||
110 | * @param array $endpoint Api request endpoint |
||
111 | * @param array $params List of parameters |
||
112 | * @param bool $raw Return data in raw format |
||
113 | * @param bool $auth |
||
114 | * |
||
115 | * @return null|object|ResponseInterface Array with data, RAW response or NULL if error |
||
116 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
117 | * @throws \ErrorException |
||
118 | * @throws \PiHole\Exceptions\EmptyResults |
||
119 | */ |
||
120 | private function doRequest(string $type, array $endpoint = null, array $params = null, bool $raw = false, bool $auth = false) |
||
135 | |||
136 | } |
||
137 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: