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 \Rezdy\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|\Psr\Http\Message\ResponseInterface |
||
40 | * @throws \GuzzleHttp\Exception\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 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
84 | * @throws \ErrorException |
||
85 | * @throws \Rezdy\Exceptions\EmptyResults |
||
86 | */ |
||
87 | public function exec() |
||
91 | |||
92 | /** |
||
93 | * Execute query and return RAW response from remote API |
||
94 | * |
||
95 | * @return null|\Psr\Http\Message\ResponseInterface RAW response or NULL if error |
||
96 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
97 | * @throws \ErrorException |
||
98 | * @throws \Rezdy\Exceptions\EmptyResults |
||
99 | */ |
||
100 | public function raw(): ?ResponseInterface |
||
104 | |||
105 | /** |
||
106 | * Make the request and analyze the result |
||
107 | * |
||
108 | * @param string $type Request method |
||
109 | * @param string $endpoint Api request endpoint |
||
110 | * @param mixed $params List of parameters |
||
111 | * @param bool $raw Return data in raw format |
||
112 | * |
||
113 | * @return null|object|ResponseInterface Array with data, RAW response or NULL if error |
||
114 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
115 | * @throws \ErrorException |
||
116 | * @throws \Rezdy\Exceptions\EmptyResults |
||
117 | */ |
||
118 | private function doRequest($type, $endpoint, $params = null, bool $raw = false) |
||
133 | |||
134 | } |
||
135 |
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: