@@ -8,111 +8,111 @@ |
||
8 | 8 | |
9 | 9 | class GuzzleHttpAdapter implements HttpInterface |
10 | 10 | { |
11 | - /** |
|
12 | - * @var ClientInterface |
|
13 | - */ |
|
14 | - protected $client; |
|
15 | - |
|
16 | - /** |
|
17 | - * @param ClientInterface $client |
|
18 | - */ |
|
19 | - public function __construct(ClientInterface $client) |
|
20 | - { |
|
21 | - $this->client = $client; |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * @param string $uri |
|
26 | - * @param array $params |
|
27 | - * @param array $headers |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function get($uri, $params = [], $headers = []) |
|
31 | - { |
|
32 | - if (!empty($params)) { |
|
33 | - $uri .= '?' . http_build_query($params); |
|
34 | - } |
|
35 | - |
|
36 | - $response = $this |
|
37 | - ->client |
|
38 | - ->get($uri, ['headers' => $headers]); |
|
39 | - |
|
40 | - return $this->parseResponse($response); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $uri |
|
45 | - * @param array $body |
|
46 | - * @param array $headers |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function post($uri, $body = [], $headers = []) |
|
50 | - { |
|
51 | - $response = $this |
|
52 | - ->client |
|
53 | - ->post( |
|
54 | - $uri, [ |
|
55 | - 'headers' => $headers, |
|
56 | - 'form_params' => $body, |
|
57 | - ] |
|
58 | - ); |
|
59 | - |
|
60 | - return $this->parseResponse($response); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $uri |
|
65 | - * @param array $body |
|
66 | - * @param array $headers |
|
67 | - * @return mixed |
|
68 | - */ |
|
69 | - public function put($uri, $body = [], $headers = []) |
|
70 | - { |
|
71 | - $response = $this |
|
72 | - ->client |
|
73 | - ->put( |
|
74 | - $uri, [ |
|
75 | - 'headers' => $headers, |
|
76 | - 'form_params' => $body, |
|
77 | - ] |
|
78 | - ); |
|
79 | - |
|
80 | - return $this->parseResponse($response); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $uri |
|
85 | - * @param array $headers |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function delete($uri, $headers = []) |
|
89 | - { |
|
90 | - $response = $this |
|
91 | - ->client |
|
92 | - ->delete($uri, ['headers' => $headers]); |
|
93 | - |
|
94 | - return $this->parseResponse($response); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $url |
|
99 | - * @return $this |
|
100 | - */ |
|
101 | - public function setBaseUrl($url) |
|
102 | - { |
|
103 | - $this->client->setBaseUrl($url); |
|
104 | - return $this; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param ResponseInterface $response |
|
109 | - * @return array|null |
|
110 | - */ |
|
111 | - protected function parseResponse(ResponseInterface $response) |
|
112 | - { |
|
113 | - $responseContents = $response->getBody()->getContents(); |
|
114 | - |
|
115 | - return json_decode($responseContents, true); |
|
116 | - } |
|
11 | + /** |
|
12 | + * @var ClientInterface |
|
13 | + */ |
|
14 | + protected $client; |
|
15 | + |
|
16 | + /** |
|
17 | + * @param ClientInterface $client |
|
18 | + */ |
|
19 | + public function __construct(ClientInterface $client) |
|
20 | + { |
|
21 | + $this->client = $client; |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * @param string $uri |
|
26 | + * @param array $params |
|
27 | + * @param array $headers |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function get($uri, $params = [], $headers = []) |
|
31 | + { |
|
32 | + if (!empty($params)) { |
|
33 | + $uri .= '?' . http_build_query($params); |
|
34 | + } |
|
35 | + |
|
36 | + $response = $this |
|
37 | + ->client |
|
38 | + ->get($uri, ['headers' => $headers]); |
|
39 | + |
|
40 | + return $this->parseResponse($response); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $uri |
|
45 | + * @param array $body |
|
46 | + * @param array $headers |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function post($uri, $body = [], $headers = []) |
|
50 | + { |
|
51 | + $response = $this |
|
52 | + ->client |
|
53 | + ->post( |
|
54 | + $uri, [ |
|
55 | + 'headers' => $headers, |
|
56 | + 'form_params' => $body, |
|
57 | + ] |
|
58 | + ); |
|
59 | + |
|
60 | + return $this->parseResponse($response); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $uri |
|
65 | + * @param array $body |
|
66 | + * @param array $headers |
|
67 | + * @return mixed |
|
68 | + */ |
|
69 | + public function put($uri, $body = [], $headers = []) |
|
70 | + { |
|
71 | + $response = $this |
|
72 | + ->client |
|
73 | + ->put( |
|
74 | + $uri, [ |
|
75 | + 'headers' => $headers, |
|
76 | + 'form_params' => $body, |
|
77 | + ] |
|
78 | + ); |
|
79 | + |
|
80 | + return $this->parseResponse($response); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $uri |
|
85 | + * @param array $headers |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function delete($uri, $headers = []) |
|
89 | + { |
|
90 | + $response = $this |
|
91 | + ->client |
|
92 | + ->delete($uri, ['headers' => $headers]); |
|
93 | + |
|
94 | + return $this->parseResponse($response); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $url |
|
99 | + * @return $this |
|
100 | + */ |
|
101 | + public function setBaseUrl($url) |
|
102 | + { |
|
103 | + $this->client->setBaseUrl($url); |
|
104 | + return $this; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param ResponseInterface $response |
|
109 | + * @return array|null |
|
110 | + */ |
|
111 | + protected function parseResponse(ResponseInterface $response) |
|
112 | + { |
|
113 | + $responseContents = $response->getBody()->getContents(); |
|
114 | + |
|
115 | + return json_decode($responseContents, true); |
|
116 | + } |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | \ No newline at end of file |