Skip to content

Commit 03bd49e

Browse files
committed
Documentation updates
1 parent 00391ea commit 03bd49e

File tree

3 files changed

+194
-2
lines changed

3 files changed

+194
-2
lines changed

docs/AGENT.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# PHP Consul API Agent
2+
3+
All interactions with the [`v1/agent`](https://www.consul.io/docs/agent/http/agent.html) endpoint are done
4+
via the [AgentClient](./src/Agent/AgentClient.php) class.
5+
6+
If you have constructed a [Client](./src/Client.php) object, this is done as so:
7+
8+
```php
9+
$agent = $client->Agent();
10+
```
11+
12+
## Actions
13+
14+
### Get "Self"
15+
16+
```php
17+
list($self, $qm, $err) = $client->Agent()->self();
18+
if (null !== $err)
19+
die($err);
20+
21+
var_dump($qm, $self);
22+
```
23+
24+
### Get Name of Node
25+
26+
```php
27+
list($nodeName, $err) = $client->Agent()->nodeName();
28+
if (null !== $err)
29+
die($err);
30+
31+
var_dump($nodeName);
32+
```
33+
34+
### Get List of Agent Checks
35+
36+
```php
37+
list($checks, $err) = $client->Agent()->checks();
38+
if (null !== $err)
39+
die($err);
40+
41+
var_dump($checks);
42+
```
43+
44+
### Get List of Agent Services
45+
46+
```php
47+
list($services, $err) = $client->Agent()->services();
48+
if (null !== $err)
49+
die($err);
50+
51+
var_dump($services);
52+
```
53+
54+
### Get List of Cluster Members
55+
56+
```php
57+
list($members, $err) = $client->Agent()->members();
58+
if (null !== $err)
59+
die($err);
60+
61+
var_dump($members);
62+
```
63+
64+
### Register Service
65+
66+
To register a service, you must first create an [AgentServiceRegistration](./src/Agent/AgentServiceRegistration.php)
67+
object. Below is a quick and sloppy example that also creates a check:
68+
69+
```php
70+
$service = new \DCarbone\PHPConsulAPI\Agent\AgentServiceRegistration(
71+
array(
72+
'Name' => 'dan test service',
73+
'Check' => new \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck(
74+
array(
75+
'HTTP' => 'http://127.0.0.1:8000',
76+
'Interval' => '10s'
77+
)
78+
)
79+
)
80+
);
81+
82+
$err = $client->Agent()->serviceRegister($service);
83+
if (null !== $err)
84+
die($err);
85+
```
86+
87+
### Deregister Service
88+
89+
```php
90+
$err = $client->Agent()->serviceDeregister('dan test service');
91+
if (null !== $err)
92+
die($err);
93+
```
94+
95+
### Register Agent Check
96+
97+
To register an agent check, you must first create an [AgentCheckRegistration](./src/Agent/AgentCheckRegistration.php)
98+
object. Below is a quick and sloppy example:
99+
100+
```php
101+
$check = new \DCarbone\PHPConsulAPI\Agent\AgentCheckRegistration(
102+
array(
103+
'Name' => 'dan test service check',
104+
'TCP' => '127.0.0.1:8000',
105+
'Interval' => '10s',
106+
'ServiceID' => 'dan test service'
107+
)
108+
);
109+
110+
$err = $client->Agent()->checkRegister($check);
111+
if (null !== $err)
112+
die($err);
113+
```
114+
115+
### Deregister Agent Check
116+
117+
```php
118+
$err = $client->Agetn()->checkDeregister('dan test service check');
119+
if (null !== $err)
120+
die($err);
121+
```
122+
123+
### Join
124+
125+
```php
126+
$err = $client->Agent()->join('address to join');
127+
if (null !== $err)
128+
die($err);
129+
```
130+
131+
### Force Leave
132+
133+
```php
134+
$err = $client->Agent()->forceLeave('node name');
135+
if (null !== $err)
136+
die($err);
137+
```
138+
139+
### Enable Service Maintenance
140+
141+
```php
142+
$err = $client->Agent()->enableServiceMaintenance('service id', 'because reasons');
143+
if (null !== $err)
144+
die($err);
145+
```
146+
147+
### Disable Service Maintenance
148+
149+
```php
150+
$err = $client->Agent()->disableServiceMaintenance('service id');
151+
if (null !== $er)
152+
die($err);
153+
```
154+
155+
### Enable Node Maintenance
156+
157+
```php
158+
$err = $client->Agent()->enableNodeMaintenance('because GOOD reasons');
159+
if (null !== $err)
160+
die($err);
161+
```
162+
163+
### Disable Node Maintenance
164+
165+
```php
166+
$err = $client->Agent()->disableNodeMaintenance();
167+
if (null !== $err)
168+
die($err);
169+
```
170+
171+
### Set TTL Check to Passing
172+
173+
```php
174+
$err = $client->Agent()->passTTL('check id', 'all good here, dudes');
175+
if (null !== $err)
176+
die($err);
177+
```
178+
179+
### Set TTL Check to Warning
180+
181+
```php
182+
$err = $client->Agent()->warnTTL('check id', 'might not be good here, dudes');
183+
if (null !== $err)
184+
die($err);
185+
```
186+
187+
### Set TTL Check to Failing
188+
189+
```php
190+
$err = $client->Agent()->failTTL('check id', 'super not good here, dudes.');
191+
if (null !== $err)
192+
die($err);
193+
```

docs/KV.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ via the [KVClient](./src/KV/KVClient.php) class.
66
If you have constructed a [Client](./src/Client.php) object, this is done as so:
77

88
```php
9-
/** @var \DCarbone\PHPConsulAPI\KV\KVClient $kv */
109
$kv = $client->KV();
1110
```
1211

src/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected function _findKeyMatches($key)
280280
$possibleMatches = array();
281281
if (is_string($key))
282282
{
283-
$regex = sprintf('{^.*%s.*$}i', $key);
283+
$regex = sprintf('{^.*%s.*$}i', substr($key, 0, 2));
284284
foreach($this as $k => $_)
285285
{
286286
if (preg_match($regex, $k))

0 commit comments

Comments
 (0)