Skip to content

Commit 4c97541

Browse files
committed
Some refactorings and adding initial SessionClient implementation
1 parent b3247ba commit 4c97541

13 files changed

+416
-68
lines changed

src/AbstractConsulClient.php renamed to src/AbstractClient.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*/
1818

1919
/**
20-
* Class AbstractConsulClient
20+
* Class AbstractClient
2121
* @package DCarbone\PHPConsulAPI\Base
2222
*/
23-
abstract class AbstractConsulClient
23+
abstract class AbstractClient
2424
{
2525
/** @var Config */
2626
protected $_Config;
@@ -68,14 +68,14 @@ protected function requireOK(array $requestResult)
6868
}
6969

7070
/**
71-
* @param Request $r
71+
* @param HttpRequest $r
7272
* @return array(
7373
* @type int duration in microseconds
7474
* @type HttpResponse|null http response
7575
* @type \DCarbone\PHPConsulAPI\Error|null any seen errors
7676
* )
7777
*/
78-
protected function doRequest(Request $r)
78+
protected function doRequest(HttpRequest $r)
7979
{
8080
$rt = microtime(true);
8181
/** @var HttpResponse $response */

src/Agent/AgentClient.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
limitations under the License.
1717
*/
1818

19-
use DCarbone\PHPConsulAPI\AbstractConsulClient;
19+
use DCarbone\PHPConsulAPI\AbstractClient;
2020
use DCarbone\PHPConsulAPI\Hydrator;
21-
use DCarbone\PHPConsulAPI\Request;
21+
use DCarbone\PHPConsulAPI\HttpRequest;
2222

2323
/**
2424
* Class AgentClient
2525
* @package DCarbone\PHPConsulAPI\Agent
2626
*/
27-
class AgentClient extends AbstractConsulClient
27+
class AgentClient extends AbstractClient
2828
{
2929
/** @var null|AgentSelf */
3030
private $_self = null;
@@ -38,7 +38,7 @@ class AgentClient extends AbstractConsulClient
3838
*/
3939
public function self()
4040
{
41-
$r = new Request('get', 'v1/agent/self', $this->_Config);
41+
$r = new HttpRequest('get', 'v1/agent/self', $this->_Config);
4242

4343
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
4444
$qm = $this->buildQueryMeta($duration, $response);
@@ -82,7 +82,7 @@ public function nodeName()
8282
*/
8383
public function checks()
8484
{
85-
$r = new Request('get', 'v1/agent/checks', $this->_Config);
85+
$r = new HttpRequest('get', 'v1/agent/checks', $this->_Config);
8686

8787
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
8888

@@ -111,7 +111,7 @@ public function checks()
111111
*/
112112
public function services()
113113
{
114-
$r = new Request('get', 'v1/agent/services', $this->_Config);
114+
$r = new HttpRequest('get', 'v1/agent/services', $this->_Config);
115115

116116
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
117117

@@ -140,7 +140,7 @@ public function services()
140140
*/
141141
public function members()
142142
{
143-
$r = new Request('get', 'v1/agent/members', $this->_Config);
143+
$r = new HttpRequest('get', 'v1/agent/members', $this->_Config);
144144

145145
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
146146

@@ -169,7 +169,7 @@ public function members()
169169
*/
170170
public function serviceRegister(AgentServiceRegistration $agentServiceRegistration)
171171
{
172-
$r = new Request('put', 'v1/agent/service/register', $this->_Config);
172+
$r = new HttpRequest('put', 'v1/agent/service/register', $this->_Config);
173173
$r->body = ($agentServiceRegistration);
174174

175175
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -185,7 +185,7 @@ public function serviceRegister(AgentServiceRegistration $agentServiceRegistrati
185185
*/
186186
public function serviceDeregister($serviceID)
187187
{
188-
$r = new Request('put', sprintf('v1/agent/service/deregister/%s', rawurlencode($serviceID)), $this->_Config);
188+
$r = new HttpRequest('put', sprintf('v1/agent/service/deregister/%s', rawurlencode($serviceID)), $this->_Config);
189189

190190
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
191191

@@ -238,7 +238,7 @@ public function failTTL($checkID, $note)
238238
*/
239239
public function updateTTL($checkID, $output, $status)
240240
{
241-
$r = new Request('put', sprintf('v1/agent/check/update/%s', rawurlencode($checkID)), $this->_Config);
241+
$r = new HttpRequest('put', sprintf('v1/agent/check/update/%s', rawurlencode($checkID)), $this->_Config);
242242
$r->body = (new AgentCheckUpdate(['Output' => $output, 'Status' => $status]));
243243

244244
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -252,7 +252,7 @@ public function updateTTL($checkID, $output, $status)
252252
*/
253253
public function checkRegister(AgentCheckRegistration $agentCheckRegistration)
254254
{
255-
$r = new Request('put', 'v1/agent/check/register', $this->_Config);
255+
$r = new HttpRequest('put', 'v1/agent/check/register', $this->_Config);
256256
$r->body = ($agentCheckRegistration);
257257

258258
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -266,7 +266,7 @@ public function checkRegister(AgentCheckRegistration $agentCheckRegistration)
266266
*/
267267
public function checkDeregister($checkID)
268268
{
269-
$r = new Request('put', sprintf('v1/agent/check/deregister/%s', rawurlencode($checkID)), $this->_Config);
269+
$r = new HttpRequest('put', sprintf('v1/agent/check/deregister/%s', rawurlencode($checkID)), $this->_Config);
270270

271271
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
272272

@@ -280,7 +280,7 @@ public function checkDeregister($checkID)
280280
*/
281281
public function join($addr, $wan = false)
282282
{
283-
$r = new Request('put', sprintf('v1/agent/join/%s', rawurlencode($addr)), $this->_Config);
283+
$r = new HttpRequest('put', sprintf('v1/agent/join/%s', rawurlencode($addr)), $this->_Config);
284284
if ($wan)
285285
$r->params->set('wan', 1);
286286

@@ -295,7 +295,7 @@ public function join($addr, $wan = false)
295295
*/
296296
public function forceLeave($node)
297297
{
298-
$r = new Request('put', sprintf('v1/agent/force-leave/%s', rawurlencode($node)), $this->_Config);
298+
$r = new HttpRequest('put', sprintf('v1/agent/force-leave/%s', rawurlencode($node)), $this->_Config);
299299

300300
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
301301

@@ -309,7 +309,7 @@ public function forceLeave($node)
309309
*/
310310
public function enableServiceMaintenance($serviceID, $reason = '')
311311
{
312-
$r = new Request('put', sprintf('v1/agent/service/maintenance/%s', rawurlencode($serviceID)), $this->_Config);
312+
$r = new HttpRequest('put', sprintf('v1/agent/service/maintenance/%s', rawurlencode($serviceID)), $this->_Config);
313313
$r->params->set('enable', 'true');
314314
$r->params->set('reason', $reason);
315315

@@ -324,7 +324,7 @@ public function enableServiceMaintenance($serviceID, $reason = '')
324324
*/
325325
public function disableServiceMaintenance($serviceID)
326326
{
327-
$r = new Request('put', sprintf('v1/agent/service/maintenance/%s', rawurlencode($serviceID)), $this->_Config);
327+
$r = new HttpRequest('put', sprintf('v1/agent/service/maintenance/%s', rawurlencode($serviceID)), $this->_Config);
328328
$r->params->set('enable', 'false');
329329

330330
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -338,7 +338,7 @@ public function disableServiceMaintenance($serviceID)
338338
*/
339339
public function enableNodeMaintenance($reason = '')
340340
{
341-
$r = new Request('put', 'v1/agent/maintenance', $this->_Config);
341+
$r = new HttpRequest('put', 'v1/agent/maintenance', $this->_Config);
342342
$r->params->set('enable', 'true');
343343
$r->params->set('reason', $reason);
344344

@@ -352,7 +352,7 @@ public function enableNodeMaintenance($reason = '')
352352
*/
353353
public function disableNodeMaintenance()
354354
{
355-
$r = new Request('put', 'v1/agent/maintenance', $this->_Config);
355+
$r = new HttpRequest('put', 'v1/agent/maintenance', $this->_Config);
356356
$r->params->set('enable', 'false');
357357

358358
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -369,7 +369,7 @@ public function disableNodeMaintenance()
369369
*/
370370
public function checkPass($checkID, $note = '')
371371
{
372-
$r = new Request('get', sprintf('v1/agent/check/pass/%s', rawurlencode($checkID)), $this->_Config);
372+
$r = new HttpRequest('get', sprintf('v1/agent/check/pass/%s', rawurlencode($checkID)), $this->_Config);
373373
$r->params->set('note', $note);
374374

375375
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -386,7 +386,7 @@ public function checkPass($checkID, $note = '')
386386
*/
387387
public function checkWarn($checkID, $note = '')
388388
{
389-
$r = new Request('get', sprintf('v1/agent/check/warn/%s', rawurlencode($checkID)), $this->_Config);
389+
$r = new HttpRequest('get', sprintf('v1/agent/check/warn/%s', rawurlencode($checkID)), $this->_Config);
390390
$r->params->set('note', $note);
391391

392392
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -403,7 +403,7 @@ public function checkWarn($checkID, $note = '')
403403
*/
404404
public function checkFail($checkID, $note = '')
405405
{
406-
$r = new Request('get', sprintf('v1/agent/check/fail/%s', rawurlencode($checkID)), $this->_Config);
406+
$r = new HttpRequest('get', sprintf('v1/agent/check/fail/%s', rawurlencode($checkID)), $this->_Config);
407407
$r->params->set('note', $note);
408408

409409
list($_, $_, $err) = $this->requireOK($this->doRequest($r));

src/Catalog/CatalogClient.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
limitations under the License.
1717
*/
1818

19-
use DCarbone\PHPConsulAPI\AbstractConsulClient;
19+
use DCarbone\PHPConsulAPI\AbstractClient;
2020
use DCarbone\PHPConsulAPI\Hydrator;
2121
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\Request;
22+
use DCarbone\PHPConsulAPI\HttpRequest;
2323
use DCarbone\PHPConsulAPI\WriteOptions;
2424

2525
/**
2626
* Class CatalogClient
2727
* @package DCarbone\PHPConsulAPI\Catalog
2828
*/
29-
class CatalogClient extends AbstractConsulClient
29+
class CatalogClient extends AbstractClient
3030
{
3131
/**
3232
* @param CatalogRegistration $catalogRegistration
@@ -38,7 +38,7 @@ class CatalogClient extends AbstractConsulClient
3838
*/
3939
public function register(CatalogRegistration $catalogRegistration, WriteOptions $writeOptions = null)
4040
{
41-
$r = new Request('put', 'v1/catalog/register', $this->_Config, $catalogRegistration);
41+
$r = new HttpRequest('put', 'v1/catalog/register', $this->_Config, $catalogRegistration);
4242
$r->setWriteOptions($writeOptions);
4343

4444
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -57,7 +57,7 @@ public function register(CatalogRegistration $catalogRegistration, WriteOptions
5757
*/
5858
public function deregister(CatalogDeregistration $catalogDeregistration, WriteOptions $writeOptions = null)
5959
{
60-
$r = new Request('put', 'v1/catalog/deregister', $this->_Config, $catalogDeregistration);
60+
$r = new HttpRequest('put', 'v1/catalog/deregister', $this->_Config, $catalogDeregistration);
6161
$r->setWriteOptions($writeOptions);
6262

6363
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -74,7 +74,7 @@ public function deregister(CatalogDeregistration $catalogDeregistration, WriteOp
7474
*/
7575
public function datacenters()
7676
{
77-
$r = new Request('get', 'v1/catalog/datacenters', $this->_Config);
77+
$r = new HttpRequest('get', 'v1/catalog/datacenters', $this->_Config);
7878

7979
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
8080

@@ -94,7 +94,7 @@ public function datacenters()
9494
*/
9595
public function nodes(QueryOptions $queryOptions = null)
9696
{
97-
$r = new Request('get', 'v1/catalog/nodes', $this->_Config);
97+
$r = new HttpRequest('get', 'v1/catalog/nodes', $this->_Config);
9898
$r->setQueryOptions($queryOptions);
9999

100100
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -128,7 +128,7 @@ public function nodes(QueryOptions $queryOptions = null)
128128
*/
129129
public function services(QueryOptions $queryOptions = null)
130130
{
131-
$r = new Request('get', 'v1/catalog/services', $this->_Config);
131+
$r = new HttpRequest('get', 'v1/catalog/services', $this->_Config);
132132
$r->setQueryOptions($queryOptions);
133133

134134
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -154,7 +154,7 @@ public function services(QueryOptions $queryOptions = null)
154154
*/
155155
public function service($service, $tag = '', QueryOptions $queryOptions = null)
156156
{
157-
$r = new Request('get', sprintf('v1/catalog/service/%s', rawurlencode($service)), $this->_Config);
157+
$r = new HttpRequest('get', sprintf('v1/catalog/service/%s', rawurlencode($service)), $this->_Config);
158158
$r->setQueryOptions($queryOptions);
159159
if ('' !== $tag)
160160
$r->params->set('tag', $tag);
@@ -191,7 +191,7 @@ public function service($service, $tag = '', QueryOptions $queryOptions = null)
191191
*/
192192
public function node($node, QueryOptions $queryOptions = null)
193193
{
194-
$r = new Request('get', sprintf('v1/catalog/node/%s', rawurlencode($node)), $this->_Config);
194+
$r = new HttpRequest('get', sprintf('v1/catalog/node/%s', rawurlencode($node)), $this->_Config);
195195
$r->setQueryOptions($queryOptions);
196196

197197
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));

src/Client.php

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use DCarbone\PHPConsulAPI\Event\EventClient;
2323
use DCarbone\PHPConsulAPI\Health\HealthClient;
2424
use DCarbone\PHPConsulAPI\KV\KVClient;
25+
use DCarbone\PHPConsulAPI\Session\SessionClient;
2526
use DCarbone\PHPConsulAPI\Status\StatusClient;
2627

2728
/**
@@ -44,6 +45,8 @@ class Client
4445
public $Health;
4546
/** @var CoordinateClient */
4647
public $Coordinate;
48+
/** @var SessionClient */
49+
public $Session;
4750

4851
/**
4952
* Client constructor.
@@ -73,5 +76,6 @@ public function __construct(Config $config = null)
7376
$this->Event = new EventClient($config);
7477
$this->Health = new HealthClient($config);
7578
$this->Coordinate = new CoordinateClient($config);
79+
$this->Session = new SessionClient($config);
7680
}
7781
}

src/Coordinate/CoordinateClient.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
limitations under the License.
1717
*/
1818

19-
use DCarbone\PHPConsulAPI\AbstractConsulClient;
19+
use DCarbone\PHPConsulAPI\AbstractClient;
2020
use DCarbone\PHPConsulAPI\Hydrator;
2121
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\Request;
22+
use DCarbone\PHPConsulAPI\HttpRequest;
2323

2424
/**
2525
* Class CoordinateClient
2626
* @package DCarbone\PHPConsulAPI\Coordinate
2727
*/
28-
class CoordinateClient extends AbstractConsulClient
28+
class CoordinateClient extends AbstractClient
2929
{
3030
/**
3131
* @return array(
@@ -35,7 +35,7 @@ class CoordinateClient extends AbstractConsulClient
3535
*/
3636
public function datacenters()
3737
{
38-
$r = new Request('get', 'v1/coordinate/datacenters', $this->_Config);
38+
$r = new HttpRequest('get', 'v1/coordinate/datacenters', $this->_Config);
3939

4040
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
4141

@@ -66,7 +66,7 @@ public function datacenters()
6666
*/
6767
public function nodes(QueryOptions $queryOptions = null)
6868
{
69-
$r = new Request('get', 'v1/coordinate/nodes', $this->_Config);
69+
$r = new HttpRequest('get', 'v1/coordinate/nodes', $this->_Config);
7070
$r->setQueryOptions($queryOptions);
7171

7272
list ($duration, $response, $err) = $this->requireOK($this->doRequest($r));

src/Event/EventClient.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
limitations under the License.
1717
*/
1818

19-
use DCarbone\PHPConsulAPI\AbstractConsulClient;
19+
use DCarbone\PHPConsulAPI\AbstractClient;
2020
use DCarbone\PHPConsulAPI\Hydrator;
2121
use DCarbone\PHPConsulAPI\QueryOptions;
22-
use DCarbone\PHPConsulAPI\Request;
22+
use DCarbone\PHPConsulAPI\HttpRequest;
2323
use DCarbone\PHPConsulAPI\WriteOptions;
2424

2525
/**
2626
* Class EventClient
2727
* @package DCarbone\PHPConsulAPI
2828
*/
29-
class EventClient extends AbstractConsulClient
29+
class EventClient extends AbstractClient
3030
{
3131
/**
3232
* @param UserEvent $event
@@ -39,7 +39,7 @@ class EventClient extends AbstractConsulClient
3939
*/
4040
public function fire(UserEvent $event, WriteOptions $writeOptions = null)
4141
{
42-
$r = new Request('put', sprintf('v1/event/fire/%s', rawurlencode($event->Name)), $this->_Config);
42+
$r = new HttpRequest('put', sprintf('v1/event/fire/%s', rawurlencode($event->Name)), $this->_Config);
4343
$r->setWriteOptions($writeOptions);
4444

4545
if ('' !== ($nf = $event->NodeFilter))
@@ -75,7 +75,7 @@ public function fire(UserEvent $event, WriteOptions $writeOptions = null)
7575
*/
7676
public function eventList($name = '', QueryOptions $queryOptions = null)
7777
{
78-
$r = new Request('get', 'v1/event/list', $this->_Config);
78+
$r = new HttpRequest('get', 'v1/event/list', $this->_Config);
7979
if ('' !== (string)$name)
8080
$r->params->set('name', $name);
8181
$r->setQueryOptions($queryOptions);

0 commit comments

Comments
 (0)