1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the KongAdminApi package. |
5
|
|
|
* |
6
|
|
|
* (c) Unikorp <https://github.com/unikorp> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Unikorp\KongAdminApi; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* abstract node |
16
|
|
|
* |
17
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractNode implements NodeInterface |
20
|
|
|
{ |
21
|
|
|
const JSON_CONTENT_TYPE = [ |
22
|
|
|
'Content-Type' => 'application/json', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* client |
27
|
|
|
* @var \Unikorp\KongAdminApi\Client $client |
28
|
|
|
*/ |
29
|
|
|
private $client = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor |
33
|
|
|
* |
34
|
|
|
* @param \Unikorp\KongAdminApi\Client $client |
35
|
|
|
*/ |
36
|
5 |
|
public function __construct(Client $client) |
37
|
|
|
{ |
38
|
5 |
|
$this->client = $client; |
39
|
5 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* get |
43
|
|
|
* |
44
|
|
|
* @param string $endpoint |
45
|
|
|
* |
46
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
47
|
|
|
*/ |
48
|
12 |
|
protected function get($endpoint) |
49
|
|
|
{ |
50
|
12 |
|
return $this->client->getHttpClient()->get($endpoint); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* post |
55
|
|
|
* |
56
|
|
|
* @param string $endpoint |
57
|
|
|
* @param DocumentInterface $document |
58
|
|
|
* |
59
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
60
|
|
|
*/ |
61
|
3 |
|
protected function post($endpoint, DocumentInterface $document = null) |
62
|
|
|
{ |
63
|
3 |
|
$body = (!is_null($document)) ? $document->toJson() : '[]'; |
64
|
|
|
|
65
|
3 |
|
return $this->client->getHttpClient()->post($endpoint, self::JSON_CONTENT_TYPE, $body); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* put |
70
|
|
|
* |
71
|
|
|
* @param string $endpoint |
72
|
|
|
* @param DocumentInterface $document |
73
|
|
|
* |
74
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
75
|
|
|
*/ |
76
|
3 |
|
protected function put($endpoint, DocumentInterface $document = null) |
77
|
|
|
{ |
78
|
3 |
|
$body = (!is_null($document)) ? $document->toJson() : '[]'; |
79
|
|
|
|
80
|
3 |
|
return $this->client->getHttpClient()->put($endpoint, self::JSON_CONTENT_TYPE, $body); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* patch |
85
|
|
|
* |
86
|
|
|
* @param string $endpoint |
87
|
|
|
* @param DocumentInterface $document |
88
|
|
|
* |
89
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
90
|
|
|
*/ |
91
|
3 |
|
protected function patch($endpoint, DocumentInterface $document = null) |
92
|
|
|
{ |
93
|
3 |
|
$body = (!is_null($document)) ? $document->toJson() : '[]'; |
94
|
|
|
|
95
|
3 |
|
return $this->client->getHttpClient()->patch($endpoint, self::JSON_CONTENT_TYPE, $body); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* delete |
100
|
|
|
* |
101
|
|
|
* @param string $endpoint |
102
|
|
|
* @param DocumentInterface $document |
103
|
|
|
* |
104
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
105
|
|
|
*/ |
106
|
4 |
|
protected function delete($endpoint, DocumentInterface $document = null) |
107
|
|
|
{ |
108
|
4 |
|
$body = (!is_null($document)) ? $document->toJson() : '[]'; |
109
|
|
|
|
110
|
4 |
|
return $this->client->getHttpClient()->delete($endpoint, self::JSON_CONTENT_TYPE, $body); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|