|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RestTemplate\Rest; |
|
4
|
|
|
|
|
5
|
|
|
use ByJG\RestServer\Exception\Error401Exception; |
|
6
|
|
|
use ByJG\RestServer\HttpRequest; |
|
7
|
|
|
use ByJG\RestServer\HttpResponse; |
|
8
|
|
|
use Psr\SimpleCache\InvalidArgumentException; |
|
9
|
|
|
use Swagger\Annotations as SWG; |
|
10
|
|
|
|
|
11
|
|
|
class SampleProtected extends ServiceAbstractBase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Sample Ping Only Authenticated |
|
15
|
|
|
* @SWG\Get( |
|
16
|
|
|
* path="/sampleprotected/ping", |
|
17
|
|
|
* tags={"zz_sampleprotected"}, |
|
18
|
|
|
* security={{ |
|
19
|
|
|
* "jwt-token":{} |
|
20
|
|
|
* }}, |
|
21
|
|
|
* @SWG\Response( |
|
22
|
|
|
* response=200, |
|
23
|
|
|
* description="The object", |
|
24
|
|
|
* @SWG\Schema( |
|
25
|
|
|
* required={"result"}, |
|
26
|
|
|
* @SWG\Property(property="result", type="string") |
|
27
|
|
|
* ) |
|
28
|
|
|
* ), |
|
29
|
|
|
* @SWG\Response( |
|
30
|
|
|
* response=401, |
|
31
|
|
|
* description="Não autorizado", |
|
32
|
|
|
* @SWG\Schema(ref="#/definitions/error") |
|
33
|
|
|
* ) |
|
34
|
|
|
* ) |
|
35
|
|
|
* |
|
36
|
|
|
* @param HttpResponse $response |
|
37
|
|
|
* @param HttpRequest $request |
|
38
|
|
|
* @throws Error401Exception |
|
39
|
|
|
* @throws InvalidArgumentException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getPing($response, $request) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$this->requireAuthenticated(); |
|
44
|
|
|
|
|
45
|
|
|
$response->write([ |
|
46
|
|
|
'result' => 'pong' |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Sample Ping Only Admin |
|
52
|
|
|
* @SWG\Get( |
|
53
|
|
|
* path="/sampleprotected/pingadm", |
|
54
|
|
|
* tags={"zz_sampleprotected"}, |
|
55
|
|
|
* security={{ |
|
56
|
|
|
* "jwt-token":{} |
|
57
|
|
|
* }}, |
|
58
|
|
|
* @SWG\Response( |
|
59
|
|
|
* response=200, |
|
60
|
|
|
* description="The object", |
|
61
|
|
|
* @SWG\Schema( |
|
62
|
|
|
* required={"result"}, |
|
63
|
|
|
* @SWG\Property(property="result", type="string") |
|
64
|
|
|
* ) |
|
65
|
|
|
* ), |
|
66
|
|
|
* @SWG\Response( |
|
67
|
|
|
* response=401, |
|
68
|
|
|
* description="Não autorizado", |
|
69
|
|
|
* @SWG\Schema(ref="#/definitions/error") |
|
70
|
|
|
* ) |
|
71
|
|
|
* ) |
|
72
|
|
|
* |
|
73
|
|
|
* @param HttpResponse $response |
|
74
|
|
|
* @param HttpRequest $request |
|
75
|
|
|
* @throws Error401Exception |
|
76
|
|
|
* @throws InvalidArgumentException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getPingAdm($response, $request) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$this->requireRole('admin'); |
|
81
|
|
|
|
|
82
|
|
|
$response->write([ |
|
83
|
|
|
'result' => 'pongadm' |
|
84
|
|
|
]); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.