1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CCT\Kong\Http\Request; |
4
|
|
|
|
5
|
|
|
use CCT\Kong\Config; |
6
|
|
|
use CCT\Kong\Http\Definition\QueryParams; |
7
|
|
|
use CCT\Kong\Http\Request; |
8
|
|
|
use CCT\Kong\Model\Api; |
9
|
|
|
use JMS\Serializer\SerializationContext; |
10
|
|
|
|
11
|
|
|
class ApiRequest extends Request |
12
|
|
|
{ |
13
|
1 |
|
protected function setUp() |
14
|
|
|
{ |
15
|
1 |
|
$this->config->set(Config::URI_PREFIX, '/apis/'); |
16
|
1 |
|
} |
17
|
|
|
|
18
|
|
|
public function list(QueryParams $queryParams = null) |
19
|
|
|
{ |
20
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups('read')); |
21
|
|
|
|
22
|
|
|
return parent::requestGet($this->getUri(), $queryParams); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function create(Api $api) |
26
|
|
|
{ |
27
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups('create')); |
28
|
|
|
|
29
|
|
|
return parent::requestPost($this->getUri(), $api, null); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function update(Api $api) |
33
|
|
|
{ |
34
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups('update')); |
35
|
|
|
|
36
|
|
|
return parent::requestPatch($this->appendToUri($api->getId()), $api, null); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function updateOrCreate(Api $api) |
40
|
|
|
{ |
41
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups([ 'update', 'create' ])); |
42
|
|
|
|
43
|
|
|
return parent::requestPut($this->appendToUri($api->getId()), $api, null); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function retrieve(string $nameOrId) |
47
|
|
|
{ |
48
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups('read')); |
49
|
|
|
|
50
|
|
|
return parent::requestGet($this->appendToUri($nameOrId), null); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function delete(string $nameOrId) |
54
|
|
|
{ |
55
|
|
|
$this->config->set('serialization_context', SerializationContext::create()->setGroups('delete')); |
56
|
|
|
|
57
|
|
|
return parent::requestDelete($this->appendToUri($nameOrId), null); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|