1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Interfaces\Controllers\IApi; |
6
|
|
|
use App\Reuse\Controllers\AbstractApi; |
7
|
|
|
use App\Container; |
8
|
|
|
use App\Http\Response; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @OA\Info(title="Nymfonya",version="v1") |
12
|
|
|
* @OA\PathItem(path=".") |
13
|
|
|
*/ |
14
|
|
|
final class Config extends AbstractApi implements IApi |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
const KEY_LENGTH = 64; |
18
|
|
|
const _TITLE = 'title'; |
19
|
|
|
const _ACTION = 'action'; |
20
|
|
|
const _DATAS = 'datas'; |
21
|
|
|
const _HOWTO = 'howto'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
8 |
|
* instanciate |
25
|
|
|
* |
26
|
8 |
|
* @param Container $container |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Container $container) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($container); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* help action |
35
|
1 |
|
* |
36
|
|
|
* @Role anonymous |
37
|
1 |
|
* @return Config |
38
|
|
|
*/ |
39
|
|
|
final public function help(): Config |
40
|
1 |
|
{ |
41
|
1 |
|
$baseUri = $this->baseRootUri(); |
42
|
1 |
|
$helpAction = [ |
43
|
|
|
[ |
44
|
|
|
self::_TITLE => 'App key generate', |
45
|
|
|
self::_ACTION => $baseUri . 'keygen', |
46
|
1 |
|
self::_HOWTO => 'Copy paste result in ' |
47
|
1 |
|
. 'config/$env jwt/secret' |
48
|
1 |
|
] |
49
|
1 |
|
]; |
50
|
|
|
$this->response |
51
|
|
|
->setCode(Response::HTTP_OK) |
52
|
|
|
->setContent($helpAction); |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
1 |
|
* false action |
58
|
|
|
* |
59
|
1 |
|
* @return boolean |
60
|
|
|
*/ |
61
|
|
|
final public function false() |
62
|
|
|
{ |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* keygen action |
68
|
1 |
|
* |
69
|
|
|
* @Role anonymous |
70
|
1 |
|
* @return Config |
71
|
1 |
|
*/ |
72
|
1 |
|
final public function keygen(): Config |
73
|
1 |
|
{ |
74
|
1 |
|
$this->response |
75
|
1 |
|
->setCode(Response::HTTP_OK) |
76
|
1 |
|
->setContent( |
77
|
1 |
|
$this->getActionItem( |
78
|
|
|
'App key generate', |
79
|
|
|
__FUNCTION__, |
80
|
|
|
base64_encode( |
81
|
1 |
|
openssl_random_pseudo_bytes(self::KEY_LENGTH) |
82
|
|
|
) |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* account action |
90
|
1 |
|
* |
91
|
|
|
* @Role anonymous |
92
|
1 |
|
* @return Config |
93
|
1 |
|
*/ |
94
|
|
|
final public function account(): Config |
95
|
|
|
{ |
96
|
1 |
|
$line = 'Undefined function readline'; |
97
|
1 |
|
if ($this->hasReadLine()) { |
98
|
1 |
|
//$line = readline("Command: "); |
99
|
1 |
|
} |
100
|
|
|
$this->response |
101
|
|
|
->setCode(Response::HTTP_OK) |
102
|
|
|
->setContent(['error' => false, 'command' => $line]); |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
1 |
|
* generate swagger doc from code |
108
|
|
|
* |
109
|
1 |
|
* @return Test |
|
|
|
|
110
|
|
|
*/ |
111
|
|
|
final public function swaggerdoc() |
112
|
|
|
{ |
113
|
|
|
$path = dirname(__FILE__); |
114
|
|
|
$controllerPath = '/Api/V1/Restful.php'; |
115
|
|
|
$openapi = \OpenApi\scan($path . $controllerPath); |
116
|
|
|
$this->response |
117
|
|
|
->setCode(Response::HTTP_OK) |
118
|
|
|
->setContent($openapi->toYaml()); |
119
|
|
|
return $this; |
120
|
1 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* return current base root uri |
124
|
1 |
|
* |
125
|
1 |
|
* @return string |
126
|
1 |
|
*/ |
127
|
|
|
protected function baseRootUri(): string |
128
|
|
|
{ |
129
|
|
|
return dirname($this->request->getUri()) . '/'; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* return array |
134
|
|
|
* |
135
|
|
|
* @param string $title |
136
|
1 |
|
* @param string $action |
137
|
|
|
* @param string $datas |
138
|
1 |
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
protected function getActionItem(string $title, string $action, string $datas): array |
141
|
|
|
{ |
142
|
|
|
return [ |
143
|
|
|
[ |
144
|
|
|
self::_TITLE => $title, |
145
|
|
|
self::_ACTION => $this->baseRootUri() . $action, |
146
|
|
|
self::_DATAS => $datas |
147
|
|
|
] |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* return true if php was configured with --readline option |
153
|
|
|
* |
154
|
|
|
* @return boolean |
155
|
|
|
*/ |
156
|
|
|
protected function hasReadLine(): bool |
157
|
|
|
{ |
158
|
|
|
return function_exists("readline"); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|