Skip to content

Commit 481eb99

Browse files
committed
Some new stuff, need to figure out logic loop of base64 stuffs....
1 parent 124c0c9 commit 481eb99

File tree

14 files changed

+422
-61
lines changed

14 files changed

+422
-61
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var_dump($kv_list);
4545
- [Agent](./docs/AGENT.md)
4646
- [Catalog](./docs/CATALOG.md)
4747
- [Status](./docs/STATUS.md)
48+
- [Event](./docs/EVENT.md)
4849

4950
More will be added as time goes on!
5051

docs/EVENT.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# PHP Consul API Event
2+
3+
All interactions with the [`v1/event`](https://www.consul.io/docs/agent/http/event.html) endpoint
4+
are done via the [EventClient](./src/Event/EventClient.php) class.
5+
6+
If you have constructed a [Client](./src/Client.php) object, this is done as so:
7+
8+
```php
9+
$event = $client->Event();
10+
```
11+
12+
## Actions
13+
14+
### Fire an Event
15+
16+
In order to fire an event, you must first create an [UserEvent](./src/Event/UserEvent.php)
17+
object.
18+
19+
Below is a quick example:
20+
21+
```php
22+
$event = new
23+
```

docs/STATUS.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# PHP Consul API Status
2+
3+
All interactions with the [`v1/status`](https://www.consul.io/docs/agent/http/status.html) endpoint
4+
are done via the [StatusClient](./src/Status/StatusClient.php) class.
5+
6+
If you have constructed a [Client](./src/Client.php) object, this is done as so:
7+
8+
```php
9+
$status = $client->Status();
10+
```
11+
12+
## Actions
13+
14+
### Leader
15+
16+
```php
17+
list($addrses, $err) = $client->Status()->leader();
18+
if (null !== $err)
19+
die($err);
20+
21+
var_dump($address);
22+
```
23+
24+
### Peers
25+
26+
```php
27+
list($peers, $err) = $client->Status()->peers();
28+
if (null !== $err)
29+
die($err);
30+
31+
var_dump($peers);
32+
```

src/AbstractConsulClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(Config $config)
3939
* @return array(
4040
* @type int query duration in microseconds
4141
* @type HttpResponse|null response object
42-
* @type Error|null error, if any
42+
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
4343
* )
4444
*/
4545
protected function requireOK(array $requestResult)
@@ -72,7 +72,7 @@ protected function requireOK(array $requestResult)
7272
* @return array(
7373
* @type int duration in microseconds
7474
* @type HttpResponse|null http response
75-
* @type Error|null any seen errors
75+
* @type \DCarbone\PHPConsulAPI\Error|null any seen errors
7676
* )
7777
*/
7878
protected function doRequest(Request $r)
@@ -131,7 +131,7 @@ protected function buildWriteMeta($duration)
131131
* @param HttpResponse $response
132132
* @return array(
133133
* @type array|string|bool|int|float decoded response
134-
* @type Error|null error, if any
134+
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
135135
* )
136136
*/
137137
protected function decodeBody(HttpResponse $response)

src/Agent/AgentClient.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
use DCarbone\PHPConsulAPI\AbstractConsulClient;
20-
use DCarbone\PHPConsulAPI\QueryMeta;
2120
use DCarbone\PHPConsulAPI\Request;
2221

2322
/**
@@ -32,7 +31,7 @@ class AgentClient extends AbstractConsulClient
3231
/**
3332
* @return array(
3433
* @type AgentSelf|null agent info or null on error
35-
* @type QueryMeta query metadata
34+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
3635
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
3736
* )
3837
*/

src/Catalog/CatalogClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function datacenters()
8989
* @param QueryOptions|null $queryOptions
9090
* @return array(
9191
* @type CatalogNode[]|null array of catalog nodes or null on error
92-
* @type QueryMeta query metadata
92+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
9393
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
9494
* )
9595
*/
@@ -123,7 +123,7 @@ public function nodes(QueryOptions $queryOptions = null)
123123
* @param QueryOptions|null $queryOptions
124124
* @return array(
125125
* @type string[]|null list of services or null on error
126-
* @type QueryMeta query metadata
126+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
127127
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
128128
* )
129129
*/
@@ -149,7 +149,7 @@ public function services(QueryOptions $queryOptions = null)
149149
* @param QueryOptions|null $queryOptions
150150
* @return array(
151151
* @type CatalogService[]|null array of services or null on error
152-
* @type QueryMeta query metadata
152+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
153153
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
154154
* )
155155
*/
@@ -186,7 +186,7 @@ public function service($service, $tag = '', QueryOptions $queryOptions = null)
186186
* @param QueryOptions|null $queryOptions
187187
* @return array(
188188
* @type CatalogNode node or null on error
189-
* @type QueryMeta query metadata
189+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
190190
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
191191
* )
192192
*/

src/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use DCarbone\PHPConsulAPI\Agent\AgentClient;
2020
use DCarbone\PHPConsulAPI\Catalog\CatalogClient;
21+
use DCarbone\PHPConsulAPI\Event\EventClient;
2122
use DCarbone\PHPConsulAPI\KV\KVClient;
2223
use DCarbone\PHPConsulAPI\Status\StatusClient;
2324

@@ -35,6 +36,8 @@ class Client
3536
private $_Catalog;
3637
/** @var StatusClient */
3738
private $_Status;
39+
/** @var EventClient */
40+
private $_Event;
3841

3942
/**
4043
* Client constructor.
@@ -61,6 +64,7 @@ public function __construct(Config $config = null)
6164
$this->_Agent = new AgentClient($config);
6265
$this->_Catalog = new CatalogClient($config);
6366
$this->_Status = new StatusClient($config);
67+
$this->_Event = new EventClient($config);
6468
}
6569

6670
/**
@@ -95,4 +99,11 @@ public function Status()
9599
return $this->_Status;
96100
}
97101

102+
/**
103+
* @return EventClient
104+
*/
105+
public function Event()
106+
{
107+
return $this->_Event;
108+
}
98109
}

src/Error.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class Error implements \JsonSerializable
3333
/**
3434
* Error constructor.
3535
* @param string $message
36-
* @internal param string $level
3736
*/
3837
public function __construct($message)
3938
{

src/Event/EventClient.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php namespace DCarbone\PHPConsulAPI\Event;
2+
3+
/*
4+
Copyright 2016 Daniel Carbone ([email protected])
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
use DCarbone\PHPConsulAPI\AbstractConsulClient;
20+
use DCarbone\PHPConsulAPI\QueryOptions;
21+
use DCarbone\PHPConsulAPI\Request;
22+
use DCarbone\PHPConsulAPI\WriteOptions;
23+
24+
/**
25+
* Class EventClient
26+
* @package DCarbone\PHPConsulAPI
27+
*/
28+
class EventClient extends AbstractConsulClient
29+
{
30+
/**
31+
* @param UserEvent $event
32+
* @param WriteOptions|null $writeOptions
33+
* @return array(
34+
* @type UserEvent|null user event that was fired or null on error
35+
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
36+
* @type \DCarbone\PHPConsulAPI\Error error, if any
37+
* )
38+
*/
39+
public function fire(UserEvent $event, WriteOptions $writeOptions = null)
40+
{
41+
$r = new Request('put', sprintf('v1/event/fire/%s', rawurlencode($event->getName())), $this->_Config);
42+
$r->setWriteOptions($writeOptions);
43+
44+
if ('' !== ($nf = $event->getNodeFilter()))
45+
$r->params()->set('node', $nf);
46+
if ('' !== ($sf = $event->getServiceFilter()))
47+
$r->params()->set('service', $sf);
48+
if ('' !== ($tf = $event->getTagFilter()))
49+
$r->params()->set('tag', $tf);
50+
if ('' !== ($payload = $event->getPayload()))
51+
$r->setBody($payload);
52+
53+
var_dump($payload);exit;
54+
55+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
56+
$wm = $this->buildWriteMeta($duration);
57+
58+
if (null !== $err)
59+
return [null, $wm, $err];
60+
61+
list($data, $err) = $this->decodeBody($response);
62+
if ($err !== null)
63+
return [null, $wm, $err];
64+
65+
return [new UserEvent($data), $wm, null];
66+
}
67+
68+
/**
69+
* @param string $name
70+
* @param QueryOptions|null $queryOptions
71+
* @return array(
72+
* @type UserEvent[] list of user events or null on error
73+
* @type \DCarbone\PHPConsulAPI\QueryMeta query metadata
74+
* @type \DCarbone\PHPConsulAPI\Error error, if any
75+
* )
76+
*/
77+
public function eventList($name = '', QueryOptions $queryOptions = null)
78+
{
79+
$r = new Request('get', 'v1/event/list', $this->_Config);
80+
if ('' !== (string)$name)
81+
$r->params()->set('name', $name);
82+
$r->setQueryOptions($queryOptions);
83+
84+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
85+
$qm = $this->buildQueryMeta($duration, $response);
86+
87+
if (null !== $err)
88+
return [null, $qm, $err];
89+
90+
list($data, $err) = $this->decodeBody($response);
91+
92+
if (null !== $err)
93+
return [null, $qm, $err];
94+
95+
$events = array();
96+
foreach($data as $event)
97+
{
98+
$events[] = new UserEvent($event);
99+
}
100+
101+
return [$events, $qm, null];
102+
}
103+
}

0 commit comments

Comments
 (0)