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\Node; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\ResponseInterface; |
15
|
|
|
use Unikorp\KongAdminApi\AbstractNode; |
16
|
|
|
use Unikorp\KongAdminApi\Document\PluginDocument as Document; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* plugin node |
20
|
|
|
* |
21
|
|
|
* @author VEBER Arnaud <https://github.com/VEBERArnaud> |
22
|
|
|
*/ |
23
|
|
|
class PluginNode extends AbstractNode |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* add plugin |
27
|
|
|
* |
28
|
|
|
* @param string $nameOrId |
29
|
|
|
* @param \Unikorp\KongAdminApi\Document\PluginDocument $document |
30
|
|
|
* |
31
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
32
|
|
|
*/ |
33
|
2 |
|
public function addPlugin(string $nameOrId, Document $document): ResponseInterface |
34
|
|
|
{ |
35
|
2 |
|
return $this->post(sprintf('/apis/%1$s/plugins/', $nameOrId), $document); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* retrieve plugin |
40
|
|
|
* |
41
|
|
|
* @param string $id |
42
|
|
|
* |
43
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
44
|
|
|
*/ |
45
|
2 |
|
public function retrievePlugin(string $id): ResponseInterface |
46
|
|
|
{ |
47
|
2 |
|
return $this->get(sprintf('/plugins/%1$s', $id)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* list all plugins |
52
|
|
|
* |
53
|
|
|
* @param \Unikorp\KongAdminApi\Document\PluginDocument $document |
54
|
|
|
* |
55
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
56
|
|
|
*/ |
57
|
2 |
|
public function listAllPlugins(Document $document = null): ResponseInterface |
58
|
|
|
{ |
59
|
2 |
|
return $this->get('/plugins/', $document); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* list plugins per api |
64
|
|
|
* |
65
|
|
|
* @param string $apiNameOrId |
66
|
|
|
* |
67
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
68
|
|
|
*/ |
69
|
2 |
|
public function listPluginsPerApi(string $apiNameOrId): ResponseInterface |
70
|
|
|
{ |
71
|
2 |
|
return $this->get(sprintf('/apis/%1$s/plugins/', $apiNameOrId)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* update plugin |
76
|
|
|
* |
77
|
|
|
* @param string $apiNameOrId |
78
|
|
|
* @param string $id |
79
|
|
|
* @param \Unikorp\KongAdminApi\Document\PluginDocument $document |
80
|
|
|
* |
81
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
82
|
|
|
*/ |
83
|
2 |
|
public function updatePlugin(string $apiNameOrId, string $id, Document $document): ResponseInterface |
84
|
|
|
{ |
85
|
2 |
|
return $this->patch(sprintf('/apis/%1$s/plugins/%2$s', $apiNameOrId, $id), $document); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* update or add plugin |
90
|
|
|
* |
91
|
|
|
* @param string $apiNameOrId |
92
|
|
|
* @param \Unikorp\KongAdminApi\Document\PluginDocument $document |
93
|
|
|
* |
94
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
95
|
|
|
*/ |
96
|
2 |
|
public function updateOrAddPlugin(string $apiNameOrId, Document $document): ResponseInterface |
97
|
|
|
{ |
98
|
2 |
|
return $this->put(sprintf('/apis/%1$s/plugins/', $apiNameOrId), $document); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* delete plugin |
103
|
|
|
* |
104
|
|
|
* @param string $apiNameOrId |
105
|
|
|
* @param string $id |
106
|
|
|
* |
107
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
108
|
|
|
*/ |
109
|
2 |
|
public function deletePlugin(string $apiNameOrId, string $id): ResponseInterface |
110
|
|
|
{ |
111
|
2 |
|
return $this->delete(sprintf('/apis/%1$s/plugins/%2$s', $apiNameOrId, $id)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* retrieve enabled plugin |
116
|
|
|
* |
117
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
118
|
|
|
*/ |
119
|
2 |
|
public function retrieveEnabledPlugin(): ResponseInterface |
120
|
|
|
{ |
121
|
2 |
|
return $this->get('/plugins/enabled'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* retrieve plugin schema |
126
|
|
|
* |
127
|
|
|
* @param string $pluginName |
128
|
|
|
* |
129
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
130
|
|
|
*/ |
131
|
2 |
|
public function retrievePluginSchema(string $pluginName): ResponseInterface |
132
|
|
|
{ |
133
|
2 |
|
return $this->get(sprintf('/plugins/schema/%1$s', $pluginName)); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|