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 Config |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * Request executor with timeout and repeat tries |
||
34 | * |
||
35 | * @param string $type Request method |
||
36 | * @param string $url endpoint url |
||
37 | * @param mixed $params List of parameters |
||
38 | * |
||
39 | * @return null|ResponseInterface |
||
40 | * @throws GuzzleException |
||
41 | * @throws ErrorException |
||
42 | */ |
||
43 | private function repeatRequest($type, $url, $params): ?ResponseInterface |
||
78 | |||
79 | /** |
||
80 | * Execute request and return response |
||
81 | * |
||
82 | * @return null|object Array with data or NULL if error |
||
83 | */ |
||
84 | public function exec() |
||
88 | |||
89 | /** |
||
90 | * Execute query and return RAW response from remote API |
||
91 | * |
||
92 | * @return null|ResponseInterface RAW response or NULL if error |
||
93 | */ |
||
94 | public function raw(): ?ResponseInterface |
||
98 | |||
99 | /** |
||
100 | * Make the request and analyze the result |
||
101 | * |
||
102 | * @param string $type Request method |
||
103 | * @param string $endpoint Api request endpoint |
||
104 | * @param mixed $params List of parameters |
||
105 | * @param bool $raw Return data in raw format |
||
106 | * |
||
107 | * @return null|object|ResponseInterface Array with data, RAW response or NULL if error |
||
108 | */ |
||
109 | private function doRequest($type, $endpoint, $params = null, bool $raw = false) |
||
132 | |||
133 | } |
||
134 |
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: