Skip to content

Commit e90719c

Browse files
committed
some bugfixes
1 parent 3dea915 commit e90719c

File tree

15 files changed

+115
-81
lines changed

15 files changed

+115
-81
lines changed

src/ACL/ACLClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function Clone(string $id, ?WriteOptions $opts = null): ValuedWriteString
9191
*/
9292
public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
9393
{
94-
$resp = $this->_doGet(\sprintf('v1/acl/info/%s', $id), $opts);
94+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/acl/info/%s', $id), $opts));
9595
$ret = new ACLEntriesResponse();
9696
$this->_hydrateResponse($resp, $ret);
9797
return $ret;
@@ -105,7 +105,7 @@ public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
105105
*/
106106
public function List(?QueryOptions $opts = null): ACLEntriesResponse
107107
{
108-
$resp = $this->_doGet('v1/acl/list', $opts);
108+
$resp = $this->_requireOK($this->_doGet('v1/acl/list', $opts));
109109
$ret = new ACLEntriesResponse();
110110
$this->_hydrateResponse($resp, $ret);
111111
return $ret;
@@ -119,7 +119,7 @@ public function List(?QueryOptions $opts = null): ACLEntriesResponse
119119
*/
120120
public function Replication(?QueryOptions $opts = null): ACLReplicationStatusResponse
121121
{
122-
$resp = $this->_doGet('/v1/acl/replication', $opts);
122+
$resp = $this->_requireOK($this->_doGet('/v1/acl/replication', $opts));
123123
$ret = new ACLReplicationStatusResponse();
124124
$this->_hydrateResponse($resp, $ret);
125125
return $ret;

src/AbstractModels.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ public function count(): int
171171
*/
172172
public function jsonSerialize(): array
173173
{
174+
if (0 === $this->_size) {
175+
return [];
176+
}
177+
174178
$out = [];
175179
foreach ($this->_list as $i => $item) {
176180
if (null === $item) {

src/Agent/AgentClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function Self(bool $refresh = false): MapResponse
4646
if (!$refresh && isset($this->_self)) {
4747
return $this->_self;
4848
}
49-
$resp = $this->_doGet('v1/agent/self', null);
49+
$resp = $this->_requireOK($this->_doGet('v1/agent/self', null));
5050
$ret = new MapResponse();
5151
$this->_hydrateResponse($resp, $ret);
5252
if (null === $ret->Err) {
@@ -75,7 +75,7 @@ public function Host(): MapResponse
7575
*/
7676
public function Metrics(): MetricsInfoResponse
7777
{
78-
$resp = $this->_doGet('v1/agent/metrics', null);
78+
$resp = $this->_requireOK($this->_doGet('v1/agent/metrics', null));
7979
$ret = new MetricsInfoResponse();
8080
$this->_hydrateResponse($resp, $ret);
8181
return $ret;
@@ -265,7 +265,7 @@ public function Service(string $serviceID, ?QueryOptions $opts = null): AgentSer
265265
*/
266266
public function Members(): AgentMembersResponse
267267
{
268-
$resp = $this->_doGet('v1/agent/members', null);
268+
$resp = $this->_requireOK($this->_doGet('v1/agent/members', null));
269269
$ret = new AgentMembersResponse();
270270
$this->_hydrateResponse($resp, $ret);
271271
return $ret;

src/Agent/AgentServiceCheck.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class AgentServiceCheck extends AbstractModel
7575
private const FIELD_TCP = 'TCP';
7676
private const FIELD_STATUS = 'Status';
7777
private const FIELD_NOTES = 'Notes';
78-
private const FIELD_TLS_SKIP_VERIFY = 'TLSSKipVerify';
78+
private const FIELD_TLS_SKIP_VERIFY = 'TLSSkipVerify';
7979
private const FIELD_GRPC = 'GRPC';
8080
private const FIELD_GRPC_USE_TLS = 'GRPCUseTLS';
8181
private const FIELD_ALIAS_NODE = 'AliasNode';
@@ -117,7 +117,7 @@ class AgentServiceCheck extends AbstractModel
117117
/** @var string */
118118
public string $GRPC = '';
119119
/** @var bool */
120-
public bool $GRPCUseTL = false;
120+
public bool $GRPCUseTLS = false;
121121
/** @var string */
122122
public string $AliasNode = '';
123123
/** @var string */
@@ -421,18 +421,18 @@ public function setGRPC(string $GRPC): self
421421
/**
422422
* @return bool
423423
*/
424-
public function isGRPCUseTL(): bool
424+
public function isGRPCUseTLS(): bool
425425
{
426-
return $this->GRPCUseTL;
426+
return $this->GRPCUseTLS;
427427
}
428428

429429
/**
430-
* @param bool $GRPCUseTL
430+
* @param bool $GRPCUseTLS
431431
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck
432432
*/
433-
public function setGRPCUseTL(bool $GRPCUseTL): self
433+
public function setGRPCUseTLS(bool $GRPCUseTLS): self
434434
{
435-
$this->GRPCUseTL = $GRPCUseTL;
435+
$this->GRPCUseTLS = $GRPCUseTLS;
436436
return $this;
437437
}
438438

src/Agent/AgentServiceRegistration.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AgentServiceRegistration extends AbstractModel
6363
],
6464
self::FIELD_CHECKS => [
6565
Hydration::FIELD_TYPE => Hydration::ARRAY,
66-
Hydration::FIELD_CLASS => AgentServiceCheck::class,
66+
Hydration::FIELD_CLASS => AgentServiceChecks::class,
6767
Hydration::FIELD_ARRAY_TYPE => Hydration::OBJECT,
6868
],
6969
self::FIELD_PROXY => [
@@ -113,7 +113,7 @@ class AgentServiceRegistration extends AbstractModel
113113
/** @var array */
114114
public array $Meta = [];
115115
/** @var \DCarbone\PHPConsulAPI\Agent\AgentWeights|null */
116-
public ?AgentWeights $AgentWeights = null;
116+
public ?AgentWeights $Weights = null;
117117
/** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck|null */
118118
public ?AgentServiceCheck $Check = null;
119119
/** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecks */
@@ -284,18 +284,18 @@ public function setMeta(array $Meta): self
284284
/**
285285
* @return \DCarbone\PHPConsulAPI\Agent\AgentWeights|null
286286
*/
287-
public function getAgentWeights(): ?AgentWeights
287+
public function getWeights(): ?AgentWeights
288288
{
289-
return $this->AgentWeights;
289+
return $this->Weights;
290290
}
291291

292292
/**
293-
* @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $AgentWeights
293+
* @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights
294294
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceRegistration
295295
*/
296-
public function setAgentWeights(?AgentWeights $AgentWeights): self
296+
public function setWeights(?AgentWeights $Weights): self
297297
{
298-
$this->AgentWeights = $AgentWeights;
298+
$this->Weights = $Weights;
299299
return $this;
300300
}
301301

src/Catalog/CatalogClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function Deregister(CatalogDeregistration $catalogDeregistration, ?WriteO
6060
*/
6161
public function Datacenters(): ValuedStringsResponse
6262
{
63-
$resp = $this->_doGet('v1/catalog/datacenters', null);
63+
$resp = $this->_requireOK($this->_doGet('v1/catalog/datacenters', null));
6464
$ret = new ValuedStringsResponse();
6565
$this->_hydrateResponse($resp, $ret);
6666
return $ret;
@@ -74,7 +74,7 @@ public function Datacenters(): ValuedStringsResponse
7474
*/
7575
public function Nodes(?QueryOptions $opts = null): CatalogNodesResponse
7676
{
77-
$resp = $this->_doGet('v1/catalog/nodes', $opts);
77+
$resp = $this->_requireOK($this->_doGet('v1/catalog/nodes', $opts));
7878
$ret = new CatalogNodesResponse();
7979
$this->_hydrateResponse($resp, $ret);
8080
return $ret;
@@ -88,7 +88,7 @@ public function Nodes(?QueryOptions $opts = null): CatalogNodesResponse
8888
*/
8989
public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
9090
{
91-
$resp = $this->_doGet('v1/catalog/services', $opts);
91+
$resp = $this->_requireOK($this->_doGet('v1/catalog/services', $opts));
9292
$ret = new ValuedQueryStringsResponse();
9393
$this->_hydrateResponse($resp, $ret);
9494
return $ret;
@@ -103,7 +103,7 @@ public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
103103
*/
104104
public function NodeServicesList(string $node, ?QueryOptions $opts = null): CatalogNodeServicesListResponse
105105
{
106-
$resp = $this->_doGet(\sprintf('v1/catalog/node-services/%s', \urlencode($node)), $opts);
106+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/node-services/%s', \urlencode($node)), $opts));
107107
$ret = new CatalogNodeServicesListResponse();
108108
$this->_hydrateResponse($resp, $ret);
109109
return $ret;
@@ -153,7 +153,7 @@ public function Service(string $service, string $tag = '', ?QueryOptions $opts =
153153
*/
154154
public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeResponse
155155
{
156-
$resp = $this->_doGet(\sprintf('v1/catalog/node/%s', $node), $opts);
156+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/node/%s', $node), $opts));
157157
$ret = new CatalogNodeResponse();
158158
$this->_hydrateResponse($resp, $ret);
159159
return $ret;
@@ -168,7 +168,7 @@ public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeRespo
168168
*/
169169
public function GatewayServices(string $gateway, ?QueryOptions $opts = null): GatewayServicesResponse
170170
{
171-
$resp = $this->_doGet(\sprintf('v1/catalog/gateway-services/%s', \urlencode($gateway)), $opts);
171+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/catalog/gateway-services/%s', \urlencode($gateway)), $opts));
172172
$ret = new GatewayServicesResponse();
173173
$this->_hydrateResponse($resp, $ret);
174174
return $ret;

src/Coordinate/CoordinateClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CoordinateClient extends AbstractClient
3636
*/
3737
public function Datacenters(): CoordinateDatacentersResponse
3838
{
39-
$resp = $this->_doGet('v1/coordinate/datacenters', null);
39+
$resp = $this->_requireOK($this->_doGet('v1/coordinate/datacenters', null));
4040
$ret = new CoordinateDatacentersResponse();
4141
$this->_hydrateResponse($resp, $ret);
4242
return $ret;
@@ -50,7 +50,7 @@ public function Datacenters(): CoordinateDatacentersResponse
5050
*/
5151
public function Nodes(?QueryOptions $opts = null): CoordinateEntriesResponse
5252
{
53-
$resp = $this->_doGet('v1/coordinate/nodes', $opts);
53+
$resp = $this->_requireOK($this->_doGet('v1/coordinate/nodes', $opts));
5454
$ret = new CoordinateEntriesResponse();
5555
$this->_hydrateResponse($resp, $ret);
5656
return $ret;
@@ -76,7 +76,7 @@ public function Update(CoordinateEntry $coordinateEntry, ?WriteOptions $opts = n
7676
*/
7777
public function Node(string $node, ?QueryOptions $opts = null): CoordinateEntriesResponse
7878
{
79-
$resp = $this->_doGet(\sprintf('v1/coordinate/node/%s', $node), $opts);
79+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/coordinate/node/%s', $node), $opts));
8080
$ret = new CoordinateEntriesResponse();
8181
$this->_hydrateResponse($resp, $ret);
8282
return $ret;

src/Health/HealthClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ public function State(string $state, ?QueryOptions $opts = null): HealthChecksRe
185185
* @param string $path
186186
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
187187
* @throws \GuzzleHttp\Exception\GuzzleException
188+
* @throws \Exception
188189
* @return \DCarbone\PHPConsulAPI\Health\HealthChecksResponse
189190
*/
190191
protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthChecksResponse
191192
{
192-
$resp = $this->_doGet($path, $opts);
193+
$resp = $this->_requireOK($this->_doGet($path, $opts));
193194
$ret = new HealthChecksResponse();
194195
$this->_hydrateResponse($resp, $ret);
195196
return $ret;
@@ -202,6 +203,7 @@ protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthCh
202203
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
203204
* @param string $healthType
204205
* @throws \GuzzleHttp\Exception\GuzzleException
206+
* @throws \Exception
205207
* @return \DCarbone\PHPConsulAPI\Health\ServiceEntriesResponse
206208
*/
207209
private function _getServiceEntries(

src/KV/KVClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function Get(string $key, ?QueryOptions $opts = null): KVPairResponse
5252

5353
$code = $resp->Response->getStatusCode();
5454

55-
if (200 === $code) {
55+
if (HTTP\StatusOK === $code) {
5656
// success response
5757
$dec = $this->_decodeBody($resp->Response->getBody());
5858
if (null !== $dec->Err) {
5959
$ret->Err = $dec->Err;
6060
} else {
6161
$ret->hydrateValue($dec->Decoded[0]);
6262
}
63-
} elseif (404 !== $code) {
63+
} elseif (HTTP\StatusNotFound !== $code) {
6464
$ret->Err = new Error(\sprintf('%s: %s', $code, $resp->Response->getReasonPhrase()));
6565
}
6666

src/Operator/OperatorClient.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@ class OperatorClient extends AbstractClient
3636
* @param \DCarbone\PHPConsulAPI\Operator\Area $area
3737
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $opts
3838
* @throws \GuzzleHttp\Exception\GuzzleException
39+
* @throws \Exception
3940
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
4041
*/
4142
public function AreaCreate(Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse
4243
{
43-
return $this->_writeIDResponse($this->_doPost('v1/operator/area', $area, $opts));
44+
return $this->_writeIDResponse($this->_requireOK($this->_doPost('v1/operator/area', $area, $opts)));
4445
}
4546

4647
/**
4748
* @param string $areaID
4849
* @param \DCarbone\PHPConsulAPI\Operator\Area $area
4950
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $opts
5051
* @throws \GuzzleHttp\Exception\GuzzleException
52+
* @throws \Exception
5153
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
5254
*/
5355
public function AreaUpdate(string $areaID, Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse
5456
{
55-
return $this->_writeIDResponse($this->_doPut(\sprintf('v1/operator/area/%s', $areaID), $area, $opts));
57+
return $this->_writeIDResponse(
58+
$this->_requireOK($this->_doPut(\sprintf('v1/operator/area/%s', $areaID), $area, $opts))
59+
);
5660
}
5761

5862
/**
@@ -64,7 +68,7 @@ public function AreaUpdate(string $areaID, Area $area, ?WriteOptions $opts = nul
6468
*/
6569
public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAreasResponse
6670
{
67-
$resp = $this->_doGet(\sprintf('v1/operator/area/%s', \urlencode($areaID)), $opts);
71+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/operator/area/%s', \urlencode($areaID)), $opts));
6872
$ret = new OperatorAreasResponse();
6973
$this->_hydrateResponse($resp, $ret);
7074
return $ret;
@@ -78,7 +82,7 @@ public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAre
7882
*/
7983
public function AreaList(?QueryOptions $opts = null): OperatorAreasResponse
8084
{
81-
$resp = $this->_doGet('v1/operator/area', $opts);
85+
$resp = $this->_requireOK($this->_doGet('v1/operator/area', $opts));
8286
$ret = new OperatorAreasResponse();
8387
$this->_hydrateResponse($resp, $ret);
8488
return $ret;
@@ -105,7 +109,7 @@ public function AreaDelete(string $areaID, ?WriteOptions $opts = null): WriteRes
105109
*/
106110
public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts = null): OperatorAreaJoinResponse
107111
{
108-
$resp = $this->_doPut(\sprintf('v1/operator/area/%s/join', $areaID), $addresses, $opts);
112+
$resp = $this->_requireOK($this->_doPut(\sprintf('v1/operator/area/%s/join', $areaID), $addresses, $opts));
109113
$ret = new OperatorAreaJoinResponse();
110114
$this->_hydrateResponse($resp, $ret);
111115
return $ret;
@@ -120,7 +124,7 @@ public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts =
120124
*/
121125
public function AreaMembers(string $areaID, ?QueryOptions $opts = null): OperatorSerfMembersResponse
122126
{
123-
$resp = $this->_doGet(\sprintf('v1/operator/area/%s/members', $areaID), $opts);
127+
$resp = $this->_requireOK($this->_doGet(\sprintf('v1/operator/area/%s/members', $areaID), $opts));
124128
$ret = new OperatorSerfMembersResponse();
125129
$this->_hydrateResponse($resp, $ret);
126130
return $ret;
@@ -134,7 +138,7 @@ public function AreaMembers(string $areaID, ?QueryOptions $opts = null): Operato
134138
*/
135139
public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorAutopilotConfigurationResponse
136140
{
137-
$resp = $this->_doGet('v1/operator/autopilot/configuration', $opts);
141+
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/configuration', $opts));
138142
$ret = new OperatorAutopilotConfigurationResponse();
139143
$this->_hydrateResponse($resp, $ret);
140144
return $ret;
@@ -148,7 +152,7 @@ public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorA
148152
*/
149153
public function AutopilotSetConfiguration(AutopilotConfiguration $conf, ?WriteOptions $opts = null): ?Error
150154
{
151-
return $this->_doPut('v1/operator/autopilot/configuration', $conf, $opts)->Err;
155+
return $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts))->Err;
152156
}
153157

154158
/**
@@ -162,7 +166,7 @@ public function AutopilotCASConfiguration(
162166
AutopilotConfiguration $conf,
163167
?WriteOptions $opts = null
164168
): ValuedBoolResponse {
165-
$resp = $this->_doPut('v1/operator/autopilot/configuration', $conf, $opts);
169+
$resp = $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts));
166170
$ret = new ValuedBoolResponse();
167171
$this->_hydrateResponse($resp, $ret);
168172
return $ret;
@@ -176,7 +180,7 @@ public function AutopilotCASConfiguration(
176180
*/
177181
public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorServerHealthsResponse
178182
{
179-
$resp = $this->_doGet('v1/operator/autopilot/health', $opts);
183+
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/health', $opts));
180184
$ret = new OperatorServerHealthsResponse();
181185
$this->_hydrateResponse($resp, $ret);
182186
return $ret;
@@ -190,7 +194,7 @@ public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorServe
190194
*/
191195
public function AutopilotState(?QueryOptions $opts = null): OperatorAutopilotStateResponse
192196
{
193-
$resp = $this->_doGet('v1/operator/autopilot/state', $opts);
197+
$resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/state', $opts));
194198
$ret = new OperatorAutopilotStateResponse();
195199
$this->_hydrateResponse($resp, $ret);
196200
return $ret;
@@ -204,7 +208,7 @@ public function AutopilotState(?QueryOptions $opts = null): OperatorAutopilotSta
204208
*/
205209
public function RaftGetConfiguration(?QueryOptions $opts = null): OperatorRaftConfigurationResponse
206210
{
207-
$resp = $this->_doGet('v1/operator/raft/configuration', $opts);
211+
$resp = $this->_requireOK($this->_doGet('v1/operator/raft/configuration', $opts));
208212
$ret = new OperatorRaftConfigurationResponse();
209213
$this->_hydrateResponse($resp, $ret);
210214
return $ret;
@@ -227,8 +231,8 @@ public function RaftRemovePeerByAddress(string $address, ?WriteOptions $opts = n
227231

228232
/**
229233
* @param \DCarbone\PHPConsulAPI\RequestResponse $resp
230-
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
231234
* @throws \Exception
235+
* @return \DCarbone\PHPConsulAPI\ValuedWriteStringResponse
232236
*/
233237
protected function _writeIDResponse(RequestResponse $resp): ValuedWriteStringResponse
234238
{

0 commit comments

Comments
 (0)