diff --git a/README.md b/README.md
index a9bce6e..797b892 100644
--- a/README.md
+++ b/README.md
@@ -30,8 +30,8 @@ Require Entry:
## Configuration
First, construct a [Config](./src/Config.php). This class is modeled quite closely after the
-[Config Struct](https://github.com/hashicorp/consul/blob/v0.7.0/api/api.go#L104) present in the
-[Consul API Subpackage](https://github.com/hashicorp/consul/blob/v0.7.0/api).
+[Config Struct](https://github.com/hashicorp/consul/blob/v0.8.3/api/api.go#L161) present in the
+[Consul API Subpackage](https://github.com/hashicorp/consul/blob/v0.8.3/api).
### Default Configuration
@@ -66,7 +66,7 @@ $config = new \DCarbone\PHPConsulAPI\Config([
#### Configuration Note:
By default, this client will attempt to locate a series of environment variables to describe much of the above
-configuration properties. See [here](./src/Config.php#L446) for that list, and see [here](./src/Consul.php#L36) for
+configuration properties. See [here](./src/Config.php#L450) for that list, and see [here](./src/Consul.php#L36) for
a list of the env var names.
For more advanced client configuration, such as proxy configuration, you must construct your own GuzzleHttp client
@@ -93,7 +93,7 @@ Next, construct a [Consul](./src/Consul.php) object:
$consul = new \DCarbone\PHPConsulAPI\Consul($config);
```
-*NOTE*: If you do not create your own config object, [Consul](./src/Consul.php#L75) will create it's own
+*NOTE*: If you do not create your own config object, [Consul](./src/Consul.php#L78) will create it's own
using [Config::newDefaultConfig()](./src/Config.php#L147) and attempt to locate a suitable HTTP Client.
Once constructed, you interact with each Consul API via it's corresponding Client class:
diff --git a/phpunit.local.xml b/phpunit.local.xml
index 1e5ff73..5fcdef0 100644
--- a/phpunit.local.xml
+++ b/phpunit.local.xml
@@ -27,6 +27,10 @@
./tests/Usage/ConfigUsageTest.php
+
+ ./tests/Usage/ConsulUsageTest.php
+
+
./tests/usage/KV/KVClientCRUDTests.php
@@ -38,7 +42,7 @@
- ./tests
+ ./src
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index b53fe96..97b65e3 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -27,15 +27,22 @@
./tests/Usage/ConfigUsageTest.php
+
+ ./tests/Usage/ConsulUsageTest.php
+
+
./tests/usage/KV/KVClientCRUDTests.php
+
+
+ ./tests/Usage/Agent/AgentClientUsageTests.php
- ./tests
+ ./src
diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php
index d180283..b57eae6 100644
--- a/src/ACL/ACLClient.php
+++ b/src/ACL/ACLClient.php
@@ -36,7 +36,7 @@ class ACLClient extends AbstractClient {
* )
*/
public function create(ACLEntry $acl, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/acl/create', $this->c, $acl);
+ $r = new Request('PUT', 'v1/acl/create', $this->config, $acl);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -64,7 +64,7 @@ public function create(ACLEntry $acl, WriteOptions $options = null) {
* )
*/
public function update(ACLEntry $acl, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/acl/update', $this->c, $acl);
+ $r = new Request('PUT', 'v1/acl/update', $this->config, $acl);
$r->setWriteOptions($options);
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -85,7 +85,7 @@ public function update(ACLEntry $acl, WriteOptions $options = null) {
* )
*/
public function destroy($id, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/acl/destroy/%s', $id), $this->c);
+ $r = new Request('PUT', sprintf('v1/acl/destroy/%s', $id), $this->config);
$r->setWriteOptions($options);
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -107,7 +107,7 @@ public function destroy($id, WriteOptions $options = null) {
* )
*/
public function cloneACL($id, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->c);
+ $r = new Request('PUT', sprintf('v1/acl/clone/%s', $id), $this->config);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -136,7 +136,7 @@ public function cloneACL($id, WriteOptions $options = null) {
* )
*/
public function info($id, QueryOptions $options = null) {
- $r = new Request('GET', sprintf('v1/acl/info/%s', $id), $this->c);
+ $r = new Request('GET', sprintf('v1/acl/info/%s', $id), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -169,7 +169,7 @@ public function info($id, QueryOptions $options = null) {
* )
*/
public function listACLs(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/acl/list', $this->c);
+ $r = new Request('GET', 'v1/acl/list', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -202,7 +202,7 @@ public function listACLs(QueryOptions $options = null) {
* )
*/
public function replication(QueryOptions $options = null) {
- $r = new Request('GET', '/v1/acl/replication', $this->c);
+ $r = new Request('GET', '/v1/acl/replication', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/AbstractClient.php b/src/AbstractClient.php
index 35b19e5..1e780ca 100644
--- a/src/AbstractClient.php
+++ b/src/AbstractClient.php
@@ -27,14 +27,23 @@
*/
abstract class AbstractClient {
/** @var Config */
- protected $c;
+ protected $config;
/**
* AbstractConsulClient constructor.
* @param Config $config
*/
public function __construct(Config $config) {
- $this->c = $config;
+ // TODO: Clone config?
+
+ $this->config = $config;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\Config
+ */
+ public function getConfig() {
+ return $this->config;
}
/**
@@ -100,8 +109,9 @@ protected function doRequest(Request $r) {
$err = null;
try {
// If we actually have a client defined...
- if (isset($this->c->HttpClient) && $this->c->HttpClient instanceof ClientInterface) {
- $response = $this->c->HttpClient->send($r->toPsrRequest(), $this->c->getGuzzleRequestOptions());
+ if (isset($this->config->HttpClient) && $this->config->HttpClient instanceof ClientInterface) {
+ $response =
+ $this->config->HttpClient->send($r->toPsrRequest(), $this->config->getGuzzleRequestOptions());
} // Otherwise, throw error to be caught below
else {
throw new \RuntimeException('Unable to execute query as no HttpClient has been defined.');
@@ -148,6 +158,10 @@ protected function buildQueryMeta($duration, ResponseInterface $response, UriInt
$qm->LastContact = (int)$h;
}
+ if ('' !== ($h = $response->getHeaderLine('X-Consul-Translate-Addresses'))) {
+ $qm->AddressTranslationEnabled = (bool)$h;
+ }
+
return $qm;
}
diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php
index 916a4e4..ab82569 100644
--- a/src/Agent/AgentClient.php
+++ b/src/Agent/AgentClient.php
@@ -37,7 +37,7 @@ class AgentClient extends AbstractClient {
* )
*/
public function self() {
- $r = new Request('GET', 'v1/agent/self', $this->c);
+ $r = new Request('GET', 'v1/agent/self', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -62,7 +62,7 @@ public function self() {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function reload() {
- $r = new Request('PUT', 'v1/agent/reload', $this->c);
+ $r = new Request('PUT', 'v1/agent/reload', $this->config);
return $this->requireOK($this->doRequest($r))[2];
}
@@ -95,7 +95,7 @@ public function nodeName() {
* )
*/
public function checks() {
- $r = new Request('GET', 'v1/agent/checks', $this->c);
+ $r = new Request('GET', 'v1/agent/checks', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -125,7 +125,7 @@ public function checks() {
* )
*/
public function services() {
- $r = new Request('GET', 'v1/agent/services', $this->c);
+ $r = new Request('GET', 'v1/agent/services', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -155,7 +155,7 @@ public function services() {
* )
*/
public function members() {
- $r = new Request('GET', 'v1/agent/members', $this->c);
+ $r = new Request('GET', 'v1/agent/members', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -185,7 +185,7 @@ public function members() {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function serviceRegister(AgentServiceRegistration $agentServiceRegistration) {
- $r = new Request('PUT', 'v1/agent/service/register', $this->c, $agentServiceRegistration);
+ $r = new Request('PUT', 'v1/agent/service/register', $this->config, $agentServiceRegistration);
return $this->requireOK($this->doRequest($r))[2];
}
@@ -197,7 +197,7 @@ public function serviceRegister(AgentServiceRegistration $agentServiceRegistrati
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function serviceDeregister($serviceID) {
- $r = new Request('PUT', sprintf('v1/agent/service/deregister/%s', $serviceID), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/service/deregister/%s', $serviceID), $this->config);
return $this->requireOK($this->doRequest($r))[2];
}
@@ -265,7 +265,7 @@ public function updateTTL($checkID, $output, $status) {
$r = new Request('PUT',
sprintf('v1/agent/check/update/%s', $checkID),
- $this->c,
+ $this->config,
new AgentCheckUpdate(['Output' => $output, 'Status' => $status]));
return $this->requireOK($this->doRequest($r))[2];
@@ -276,7 +276,7 @@ public function updateTTL($checkID, $output, $status) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function checkRegister(AgentCheckRegistration $agentCheckRegistration) {
- $r = new Request('PUT', 'v1/agent/check/register', $this->c, $agentCheckRegistration);
+ $r = new Request('PUT', 'v1/agent/check/register', $this->config, $agentCheckRegistration);
return $this->requireOK($this->doRequest($r))[2];
}
@@ -286,7 +286,7 @@ public function checkRegister(AgentCheckRegistration $agentCheckRegistration) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function checkDeregister($checkID) {
- $r = new Request('PUT', sprintf('v1/agent/check/deregister/%s', $checkID), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/check/deregister/%s', $checkID), $this->config);
return $this->requireOK($this->doRequest($r))[2];
}
@@ -297,7 +297,7 @@ public function checkDeregister($checkID) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function join($addr, $wan = false) {
- $r = new Request('PUT', sprintf('v1/agent/join/%s', $addr), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/join/%s', $addr), $this->config);
if ($wan) {
$r->params->set('wan', '1');
}
@@ -312,7 +312,7 @@ public function join($addr, $wan = false) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function forceLeave($node) {
- $r = new Request('PUT', sprintf('v1/agent/force-leave/%s', $node), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/force-leave/%s', $node), $this->config);
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -325,7 +325,7 @@ public function forceLeave($node) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function enableServiceMaintenance($serviceID, $reason = '') {
- $r = new Request('PUT', sprintf('v1/agent/service/maintenance/%s', $serviceID), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/service/maintenance/%s', $serviceID), $this->config);
$r->params->set('enable', 'true');
$r->params->set('reason', $reason);
@@ -339,7 +339,7 @@ public function enableServiceMaintenance($serviceID, $reason = '') {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function disableServiceMaintenance($serviceID) {
- $r = new Request('PUT', sprintf('v1/agent/service/maintenance/%s', $serviceID), $this->c);
+ $r = new Request('PUT', sprintf('v1/agent/service/maintenance/%s', $serviceID), $this->config);
$r->params->set('enable', 'false');
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -352,7 +352,7 @@ public function disableServiceMaintenance($serviceID) {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function enableNodeMaintenance($reason = '') {
- $r = new Request('PUT', 'v1/agent/maintenance', $this->c);
+ $r = new Request('PUT', 'v1/agent/maintenance', $this->config);
$r->params->set('enable', 'true');
$r->params->set('reason', $reason);
@@ -365,7 +365,7 @@ public function enableNodeMaintenance($reason = '') {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function disableNodeMaintenance() {
- $r = new Request('PUT', 'v1/agent/maintenance', $this->c);
+ $r = new Request('PUT', 'v1/agent/maintenance', $this->config);
$r->params->set('enable', 'false');
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -377,7 +377,7 @@ public function disableNodeMaintenance() {
* @return \DCarbone\PHPConsulAPI\Error|null
*/
public function leave() {
- $r = new Request('PUT', 'v1/agent/leave', $this->c);
+ $r = new Request('PUT', 'v1/agent/leave', $this->config);
list($_, $_, $err) = $this->requireOK($this->doRequest($r));
diff --git a/src/Catalog/CatalogClient.php b/src/Catalog/CatalogClient.php
index 110fd39..77926f7 100644
--- a/src/Catalog/CatalogClient.php
+++ b/src/Catalog/CatalogClient.php
@@ -35,7 +35,7 @@ class CatalogClient extends AbstractClient {
* )
*/
public function register(CatalogRegistration $catalogRegistration, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/catalog/register', $this->c, $catalogRegistration);
+ $r = new Request('PUT', 'v1/catalog/register', $this->config, $catalogRegistration);
$r->setWriteOptions($options);
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -55,7 +55,7 @@ public function register(CatalogRegistration $catalogRegistration, WriteOptions
* )
*/
public function deregister(CatalogDeregistration $catalogDeregistration, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/catalog/deregister', $this->c, $catalogDeregistration);
+ $r = new Request('PUT', 'v1/catalog/deregister', $this->config, $catalogDeregistration);
$r->setWriteOptions($options);
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -73,7 +73,7 @@ public function deregister(CatalogDeregistration $catalogDeregistration, WriteOp
* )
*/
public function datacenters() {
- $r = new Request('GET', 'v1/catalog/datacenters', $this->c);
+ $r = new Request('GET', 'v1/catalog/datacenters', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -94,7 +94,7 @@ public function datacenters() {
* )
*/
public function nodes(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/catalog/nodes', $this->c);
+ $r = new Request('GET', 'v1/catalog/nodes', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -129,7 +129,7 @@ public function nodes(QueryOptions $options = null) {
* )
*/
public function services(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/catalog/services', $this->c);
+ $r = new Request('GET', 'v1/catalog/services', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -156,7 +156,7 @@ public function services(QueryOptions $options = null) {
* )
*/
public function service($service, $tag = '', QueryOptions $options = null) {
- $r = new Request('GET', sprintf('v1/catalog/service/%s', $service), $this->c);
+ $r = new Request('GET', sprintf('v1/catalog/service/%s', $service), $this->config);
$r->setQueryOptions($options);
if ('' !== $tag) {
$r->params->set('tag', $tag);
@@ -195,7 +195,7 @@ public function service($service, $tag = '', QueryOptions $options = null) {
* )
*/
public function node($node, QueryOptions $options = null) {
- $r = new Request('GET', sprintf('v1/catalog/node/%s', $node), $this->c);
+ $r = new Request('GET', sprintf('v1/catalog/node/%s', $node), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/Coordinate/CoordinateClient.php b/src/Coordinate/CoordinateClient.php
index 428b1d1..56546e5 100644
--- a/src/Coordinate/CoordinateClient.php
+++ b/src/Coordinate/CoordinateClient.php
@@ -32,7 +32,7 @@ class CoordinateClient extends AbstractClient {
* )
*/
public function datacenters() {
- $r = new Request('GET', 'v1/coordinate/datacenters', $this->c);
+ $r = new Request('GET', 'v1/coordinate/datacenters', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -64,7 +64,7 @@ public function datacenters() {
* )
*/
public function nodes(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/coordinate/nodes', $this->c);
+ $r = new Request('GET', 'v1/coordinate/nodes', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/Event/EventClient.php b/src/Event/EventClient.php
index e70101a..5dcd0a6 100644
--- a/src/Event/EventClient.php
+++ b/src/Event/EventClient.php
@@ -39,7 +39,7 @@ public function fire(UserEvent $event, WriteOptions $options = null) {
$r = new Request(
'PUT',
sprintf('v1/event/fire/%s', $event->Name),
- $this->c,
+ $this->config,
'' !== $event->Payload ? $event->Payload : null);
$r->setWriteOptions($options);
@@ -80,7 +80,7 @@ public function fire(UserEvent $event, WriteOptions $options = null) {
* )
*/
public function eventList($name = '', QueryOptions $options = null) {
- $r = new Request('GET', 'v1/event/list', $this->c);
+ $r = new Request('GET', 'v1/event/list', $this->config);
if ('' !== (string)$name) {
$r->params->set('name', $name);
}
diff --git a/src/Health/HealthClient.php b/src/Health/HealthClient.php
index 8e45b3a..d8703e3 100644
--- a/src/Health/HealthClient.php
+++ b/src/Health/HealthClient.php
@@ -46,7 +46,7 @@ public function node($node, QueryOptions $options = null) {
))];
}
- $r = new Request('GET', sprintf('v1/health/node/%s', $node), $this->c);
+ $r = new Request('GET', sprintf('v1/health/node/%s', $node), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -92,7 +92,7 @@ public function checks($service, QueryOptions $options = null) {
}
/** @var \Psr\Http\Message\ResponseInterface $response */
- $r = new Request('GET', sprintf('v1/health/checks/%s', $service), $this->c);
+ $r = new Request('GET', sprintf('v1/health/checks/%s', $service), $this->config);
$r->setQueryOptions($options);
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -138,7 +138,7 @@ public function service($service, $tag = '', $passingOnly = false, QueryOptions
))];
}
- $r = new Request('GET', sprintf('v1/health/service/%s', $service), $this->c);
+ $r = new Request('GET', sprintf('v1/health/service/%s', $service), $this->config);
$r->setQueryOptions($options);
if ('' !== $tag) {
$r->params->set('tag', $tag);
@@ -192,7 +192,7 @@ public function state($state, QueryOptions $options = null) {
))];
}
- $r = new Request('GET', sprintf('v1/health/state/%s', $state), $this->c);
+ $r = new Request('GET', sprintf('v1/health/state/%s', $state), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/KV/KVClient.php b/src/KV/KVClient.php
index 3b0ad94..1d22dc2 100644
--- a/src/KV/KVClient.php
+++ b/src/KV/KVClient.php
@@ -47,7 +47,7 @@ public function get($key, QueryOptions $options = null) {
))];
}
- $r = new Request('GET', sprintf('v1/kv/%s', $key), $this->c);
+ $r = new Request('GET', sprintf('v1/kv/%s', $key), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -86,7 +86,7 @@ public function get($key, QueryOptions $options = null) {
* )
*/
public function put(KVPair $p, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->c, $p->Value);
+ $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->config, $p->Value);
$r->setWriteOptions($options);
if (0 !== $p->Flags) {
$r->params->set('flags', (string)$p->Flags);
@@ -109,7 +109,7 @@ public function put(KVPair $p, WriteOptions $options = null) {
* )
*/
public function delete($key, WriteOptions $options = null) {
- $r = new Request('DELETE', sprintf('v1/kv/%s', $key), $this->c);
+ $r = new Request('DELETE', sprintf('v1/kv/%s', $key), $this->config);
$r->setWriteOptions($options);
list ($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -131,9 +131,9 @@ public function delete($key, WriteOptions $options = null) {
*/
public function valueList($prefix = '', QueryOptions $options = null) {
if (null === $prefix) {
- $r = new Request('GET', 'v1/kv/', $this->c);
+ $r = new Request('GET', 'v1/kv/', $this->config);
} else if (is_string($prefix)) {
- $r = new Request('GET', sprintf('v1/kv/%s', $prefix), $this->c);
+ $r = new Request('GET', sprintf('v1/kv/%s', $prefix), $this->config);
} else {
return [null,
null,
@@ -181,9 +181,9 @@ public function valueList($prefix = '', QueryOptions $options = null) {
*/
public function keys($prefix = null, QueryOptions $options = null) {
if (null === $prefix) {
- $r = new Request('GET', 'v1/kv/', $this->c);
+ $r = new Request('GET', 'v1/kv/', $this->config);
} else if (is_string($prefix)) {
- $r = new Request('GET', sprintf('v1/kv/%s', $prefix), $this->c);
+ $r = new Request('GET', sprintf('v1/kv/%s', $prefix), $this->config);
} else {
return [null,
null,
@@ -219,7 +219,7 @@ public function keys($prefix = null, QueryOptions $options = null) {
* )
*/
public function cas(KVPair $p, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->c);
+ $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->config);
$r->setWriteOptions($options);
$r->params->set('cas', (string)$p->ModifyIndex);
if (0 !== $p->Flags) {
@@ -243,7 +243,7 @@ public function cas(KVPair $p, WriteOptions $options = null) {
* )
*/
public function acquire(KVPair $p, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->c);
+ $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->config);
$r->setWriteOptions($options);
$r->params->set('acquire', $p->Session);
if (0 !== $p->Flags) {
@@ -267,7 +267,7 @@ public function acquire(KVPair $p, WriteOptions $options = null) {
* )
*/
public function release(KVPair $p, WriteOptions $options = null) {
- $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->c);
+ $r = new Request('PUT', sprintf('v1/kv/%s', $p->Key), $this->config);
$r->setWriteOptions($options);
$r->params->set('release', $p->Session);
if (0 !== $p->Flags) {
diff --git a/src/Operator/OperatorClient.php b/src/Operator/OperatorClient.php
index d9873bd..16284af 100644
--- a/src/Operator/OperatorClient.php
+++ b/src/Operator/OperatorClient.php
@@ -35,7 +35,7 @@ class OperatorClient extends AbstractClient {
* )
*/
public function raftGetConfiguration(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/operator/raft/configuration', $this->c);
+ $r = new Request('GET', 'v1/operator/raft/configuration', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -61,7 +61,7 @@ public function raftGetConfiguration(QueryOptions $options = null) {
* @return \DCarbone\PHPConsulAPI\Error|null error, if any
*/
public function raftRemovePeerByAddress($address, WriteOptions $options = null) {
- $r = new Request('DELETE', 'v1/operator/raft/peer', $this->c);
+ $r = new Request('DELETE', 'v1/operator/raft/peer', $this->config);
$r->setWriteOptions($options);
$r->params->set('address', (string)$address);
diff --git a/src/PreparedQuery/PreparedQueryClient.php b/src/PreparedQuery/PreparedQueryClient.php
index b8e8cf0..018d163 100644
--- a/src/PreparedQuery/PreparedQueryClient.php
+++ b/src/PreparedQuery/PreparedQueryClient.php
@@ -36,7 +36,7 @@ class PreparedQueryClient extends AbstractClient {
* )
*/
public function create(PreparedQueryDefinition $query, WriteOptions $options = null) {
- $r = new Request('POST', 'v1/query', $this->c, $query);
+ $r = new Request('POST', 'v1/query', $this->config, $query);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -57,7 +57,7 @@ public function create(PreparedQueryDefinition $query, WriteOptions $options = n
* )
*/
public function update(PreparedQueryDefinition $query, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/query', $this->c, $query);
+ $r = new Request('PUT', 'v1/query', $this->config, $query);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -78,7 +78,7 @@ public function update(PreparedQueryDefinition $query, WriteOptions $options = n
* )
*/
public function listQueries(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/query', $this->c);
+ $r = new Request('GET', 'v1/query', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -111,7 +111,7 @@ public function listQueries(QueryOptions $options = null) {
* )
*/
public function get($queryID, QueryOptions $options = null) {
- $r = new Request('GET', sprintf('v1/query/%s', $queryID), $this->c);
+ $r = new Request('GET', sprintf('v1/query/%s', $queryID), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -143,7 +143,7 @@ public function get($queryID, QueryOptions $options = null) {
* )
*/
public function delete($queryID, WriteOptions $options = null) {
- $r = new Request('DELETE', sprintf('v1/query/%s', $queryID), $this->c);
+ $r = new Request('DELETE', sprintf('v1/query/%s', $queryID), $this->config);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -167,7 +167,7 @@ public function delete($queryID, WriteOptions $options = null) {
* )
*/
public function execute($queryIDOrName, QueryOptions $options = null) {
- $r = new Request('GET', sprintf('v1/query/%s/execute', $queryIDOrName), $this->c);
+ $r = new Request('GET', sprintf('v1/query/%s/execute', $queryIDOrName), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/QueryMeta.php b/src/QueryMeta.php
index 0077ebe..d98fd69 100644
--- a/src/QueryMeta.php
+++ b/src/QueryMeta.php
@@ -31,6 +31,8 @@ class QueryMeta {
public $KnownLeader = false;
/** @var int */
public $RequestTime = 0;
+ /** @var bool */
+ public $AddressTranslationEnabled = false;
/**
* @return string
@@ -66,4 +68,11 @@ public function isKnownLeader() {
public function getRequestTime() {
return $this->RequestTime;
}
+
+ /**
+ * @return bool
+ */
+ public function isAddressTranslationEnabled() {
+ return $this->AddressTranslationEnabled;
+ }
}
\ No newline at end of file
diff --git a/src/QueryOptions.php b/src/QueryOptions.php
index a9a3f51..9db3d1d 100644
--- a/src/QueryOptions.php
+++ b/src/QueryOptions.php
@@ -39,6 +39,7 @@ class QueryOptions extends AbstractModel {
public $NodeMeta = [];
/** @var int */
public $RelayFactor = 0;
+
/** @var bool */
public $Pretty = false;
diff --git a/src/Request.php b/src/Request.php
index d1d731d..2eb1d4b 100644
--- a/src/Request.php
+++ b/src/Request.php
@@ -153,6 +153,9 @@ public function setQueryOptions(QueryOptions $options = null) {
if ('' !== $options->RelayFactor) {
$this->params->set('relay-factor', (string)$options->RelayFactor);
}
+ if ($options->Pretty) {
+ $this->params->set('pretty', '');
+ }
$this->uri = null;
}
diff --git a/src/Session/SessionClient.php b/src/Session/SessionClient.php
index 2a718ed..012102c 100644
--- a/src/Session/SessionClient.php
+++ b/src/Session/SessionClient.php
@@ -46,7 +46,7 @@ public function createNoChecks(SessionEntry $sessionEntry = null, WriteOptions $
$sessionEntry->Checks = [];
}
- $r = new Request('PUT', 'v1/session/create', $this->c, $sessionEntry);
+ $r = new Request('PUT', 'v1/session/create', $this->config, $sessionEntry);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -75,7 +75,7 @@ public function createNoChecks(SessionEntry $sessionEntry = null, WriteOptions $
* )
*/
public function create(SessionEntry $sessionEntry = null, WriteOptions $options = null) {
- $r = new Request('PUT', 'v1/session/create', $this->c, $sessionEntry);
+ $r = new Request('PUT', 'v1/session/create', $this->config, $sessionEntry);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -113,7 +113,7 @@ public function destroy($id, WriteOptions $options = null) {
))];
}
- $r = new Request('PUT', sprintf('v1/session/destroy/%s', $id), $this->c);
+ $r = new Request('PUT', sprintf('v1/session/destroy/%s', $id), $this->config);
$r->setWriteOptions($options);
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
@@ -144,7 +144,7 @@ public function renew($id, WriteOptions $options = null) {
))];
}
- $r = new Request('PUT', sprintf('v1/session/renew/%s', $id), $this->c);
+ $r = new Request('PUT', sprintf('v1/session/renew/%s', $id), $this->config);
$r->setWriteOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -201,7 +201,7 @@ public function info($id, QueryOptions $options = null) {
))];
}
- $r = new Request('GET', sprintf('v1/session/info/%s', $id), $this->c);
+ $r = new Request('GET', sprintf('v1/session/info/%s', $id), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -245,7 +245,7 @@ public function node($node, QueryOptions $options = null) {
))];
}
- $r = new Request('GET', sprintf('v1/session/node/%s', $node), $this->c);
+ $r = new Request('GET', sprintf('v1/session/node/%s', $node), $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
@@ -274,7 +274,7 @@ public function node($node, QueryOptions $options = null) {
* )
*/
public function listSessions(QueryOptions $options = null) {
- $r = new Request('GET', 'v1/session/list', $this->c);
+ $r = new Request('GET', 'v1/session/list', $this->config);
$r->setQueryOptions($options);
/** @var \Psr\Http\Message\ResponseInterface $response */
diff --git a/src/Status/StatusClient.php b/src/Status/StatusClient.php
index 31e9a26..57dc3a0 100644
--- a/src/Status/StatusClient.php
+++ b/src/Status/StatusClient.php
@@ -31,7 +31,7 @@ class StatusClient extends AbstractClient {
* )
*/
public function leader() {
- $r = new Request('GET', 'v1/status/leader', $this->c);
+ $r = new Request('GET', 'v1/status/leader', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
@@ -47,7 +47,7 @@ public function leader() {
* @return array|null
*/
public function peers() {
- $r = new Request('GET', 'v1/status/peers', $this->c);
+ $r = new Request('GET', 'v1/status/peers', $this->config);
/** @var \Psr\Http\Message\ResponseInterface $response */
list($_, $response, $err) = $this->requireOK($this->doRequest($r));
diff --git a/tests/Usage/ConsulUsageTest.php b/tests/Usage/ConsulUsageTest.php
new file mode 100644
index 0000000..85629fe
--- /dev/null
+++ b/tests/Usage/ConsulUsageTest.php
@@ -0,0 +1,85 @@
+assertInstanceOf(Consul::class, $consul);
+ }
+
+ /**
+ * @depends testCanConstructWithoutConfig
+ */
+ public function testConsulHasClientsAsProperties() {
+ $this->assertClassHasAttribute('ACL', Consul::class);
+ $this->assertClassHasAttribute('Agent', Consul::class);
+ $this->assertClassHasAttribute('Catalog', Consul::class);
+ $this->assertClassHasAttribute('Coordinate', Consul::class);
+ $this->assertClassHasAttribute('Event', Consul::class);
+ $this->assertClassHasAttribute('Health', Consul::class);
+ $this->assertClassHasAttribute('KV', Consul::class);
+ $this->assertClassHasAttribute('Operator', Consul::class);
+ $this->assertClassHasAttribute('PreparedQuery', Consul::class);
+ $this->assertClassHasAttribute('Session', Consul::class);
+ $this->assertClassHasAttribute('Status', Consul::class);
+
+ $consul = new Consul();
+
+ $this->assertInstanceOf(ACLClient::class, $consul->ACL);
+ $this->assertInstanceOf(AgentClient::class, $consul->Agent);
+ $this->assertInstanceOf(CatalogClient::class, $consul->Catalog);
+ $this->assertInstanceOf(CoordinateClient::class, $consul->Coordinate);
+ $this->assertInstanceOf(EventClient::class, $consul->Event);
+ $this->assertInstanceOf(HealthClient::class, $consul->Health);
+ $this->assertInstanceOf(KVClient::class, $consul->KV);
+ $this->assertInstanceOf(OperatorClient::class, $consul->Operator);
+ $this->assertInstanceOf(PreparedQueryClient::class, $consul->PreparedQuery);
+ $this->assertInstanceOf(SessionClient::class, $consul->Session);
+ $this->assertInstanceOf(StatusClient::class, $consul->Status);
+ }
+
+ /**
+ * @depends testConsulHasClientsAsProperties
+ */
+ public function testCanConstructWithConfig() {
+ $config = new Config(['Address' => '123.456.789:8500']);
+ $consul = new Consul($config);
+ $this->assertInstanceOf(Consul::class, $consul);
+
+ $this->assertEquals('123.456.789:8500', $consul->KV->getConfig()->getAddress());
+ }
+}
\ No newline at end of file