Skip to content

Commit ffb353d

Browse files
committed
Removing custom Uri implementation
1 parent 080c4bd commit ffb353d

File tree

4 files changed

+25
-303
lines changed

4 files changed

+25
-303
lines changed

src/AbstractClient.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Http\Client\HttpClient;
2020
use Psr\Http\Message\ResponseInterface;
2121
use Psr\Http\Message\StreamInterface;
22+
use Psr\Http\Message\UriInterface;
2223

2324
/**
2425
* Class AbstractClient
@@ -122,10 +123,10 @@ protected function doRequest(Request $r) {
122123
/**
123124
* @param int $duration
124125
* @param ResponseInterface $response
125-
* @param Uri $uri
126+
* @param UriInterface $uri
126127
* @return QueryMeta
127128
*/
128-
protected function buildQueryMeta($duration, ResponseInterface $response, Uri $uri) {
129+
protected function buildQueryMeta($duration, ResponseInterface $response, UriInterface $uri) {
129130
$qm = new QueryMeta();
130131

131132
$qm->RequestTime = $duration;
@@ -170,17 +171,16 @@ protected function buildWriteMeta($duration) {
170171
*/
171172
protected function decodeBody(StreamInterface $body) {
172173
$data = @json_decode((string)$body, true);
173-
$err = json_last_error();
174174

175-
if (JSON_ERROR_NONE === $err) {
175+
if (JSON_ERROR_NONE === json_last_error()) {
176176
return [$data, null];
177177
}
178178

179179
return [null,
180180
new Error(sprintf(
181181
'%s - Unable to parse response as JSON. Message: %s',
182182
get_class($this),
183-
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : (string)$err
183+
json_last_error_msg()
184184
))];
185185
}
186186
}

src/Request.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use GuzzleHttp\Psr7\Request as Psr7Request;
2020
use GuzzleHttp\Psr7\Stream as Psr7Stream;
21+
use GuzzleHttp\Psr7\Uri;
2122

2223
/**
2324
* Class Request
@@ -35,7 +36,7 @@ class Request {
3536
/** @var string */
3637
private $path;
3738

38-
/** @var \DCarbone\PHPConsulAPI\Uri */
39+
/** @var \Psr\Http\Message\UriInterface */
3940
private $uri;
4041

4142
/** @var string */
@@ -152,6 +153,8 @@ public function setQueryOptions(QueryOptions $options = null) {
152153
if ('' !== $options->RelayFactor) {
153154
$this->params->set('relay-factor', (string)$options->RelayFactor);
154155
}
156+
157+
$this->uri = null;
155158
}
156159

157160
/**
@@ -175,14 +178,20 @@ public function setWriteOptions(WriteOptions $options = null) {
175178
if (0 !== $options->RelayFactor) {
176179
$this->params->set('relay-factor', (string)$options->RelayFactor);
177180
}
181+
182+
$this->uri = null;
178183
}
179184

180185
/**
181-
* @return \DCarbone\PHPConsulAPI\Uri
186+
* @return \Psr\Http\Message\UriInterface
182187
*/
183188
public function getUri() {
184189
if (!isset($this->uri)) {
185-
$this->uri = new Uri($this->path, $this->config, $this->params);
190+
$uri = sprintf('%s://%s/%s', $this->config->getScheme(), $this->config->Address, $this->path);
191+
if (0 < count($this->params)) {
192+
$uri = sprintf('%s?%s', $uri, (string)$this->params);
193+
}
194+
$this->uri = new Uri($uri);
186195
}
187196

188197
return $this->uri;

src/Uri.php

-294
This file was deleted.

0 commit comments

Comments
 (0)