1414use function Flextype \Component \I18n \__ ;
1515use function random_bytes ;
1616use function time ;
17- use Flextype \App \Foundation \Container ;
1817
19- class ApiAccessController extends Container
18+
19+ class ApiAccessController
2020{
21+ /**
22+ * Flextype Application
23+ */
24+ protected $ flextype ;
25+
26+ /**
27+ * __construct
28+ */
29+ public function __construct ($ flextype )
30+ {
31+ $ this ->flextype = $ flextype ;
32+ }
33+
2134 /**
2235 * Access Index page
2336 *
@@ -37,26 +50,26 @@ public function index(Request $request, Response $response) : Response
3750 }
3851 }
3952
40- return $ this ->twig ->render (
53+ return $ this ->flextype -> container ( ' twig ' ) ->render (
4154 $ response ,
4255 'plugins/admin/templates/system/api/access/index.html ' ,
4356 [
4457 'menu_item ' => 'api ' ,
4558 'tokens ' => $ tokens ,
4659 'links ' => [
4760 'api ' => [
48- 'link ' => $ this ->router ->pathFor ('admin.api.index ' ),
61+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api.index ' ),
4962 'title ' => __ ('admin_api ' ),
5063 ],
5164 'api_Access ' => [
52- 'link ' => $ this ->router ->pathFor ('admin.api_access.index ' ),
65+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ),
5366 'title ' => __ ('admin_access ' ),
5467 'active ' => true
5568 ],
5669 ],
5770 'buttons ' => [
5871 'api_access_add ' => [
59- 'link ' => $ this ->router ->pathFor ('admin.api_access.add ' ),
72+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.add ' ),
6073 'title ' => __ ('admin_create_new_token ' )
6174 ],
6275 ],
@@ -72,22 +85,22 @@ public function index(Request $request, Response $response) : Response
7285 */
7386 public function add (Request $ request , Response $ response ) : Response
7487 {
75- return $ this ->twig ->render (
88+ return $ this ->flextype -> container ( ' twig ' ) ->render (
7689 $ response ,
7790 'plugins/admin/templates/system/api/access/add.html ' ,
7891 [
7992 'menu_item ' => 'api ' ,
8093 'links ' => [
8194 'api ' => [
82- 'link ' => $ this ->router ->pathFor ('admin.api.index ' ),
95+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api.index ' ),
8396 'title ' => __ ('admin_api ' ),
8497 ],
8598 'api_access ' => [
86- 'link ' => $ this ->router ->pathFor ('admin.api_access.index ' ),
99+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ),
87100 'title ' => __ ('admin_access ' )
88101 ],
89102 'api_access_add ' => [
90- 'link ' => $ this ->router ->pathFor ('admin.api_access.add ' ),
103+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.add ' ),
91104 'title ' => __ ('admin_create_new_token ' ),
92105 'active ' => true
93106 ],
@@ -121,12 +134,12 @@ public function addProcess(Request $request, Response $response) : Response
121134 $ uuid = Uuid::uuid4 ()->toString ();
122135
123136 // Get time
124- $ time = date ($ this ->registry ->get ('flextype.settings.date_format ' ), time ());
137+ $ time = date ($ this ->flextype -> container ( ' registry ' ) ->get ('flextype.settings.date_format ' ), time ());
125138
126139 // Create API Token account
127140 if (Filesystem::write (
128141 $ api_token_file_path ,
129- $ this ->yaml ->encode ([
142+ $ this ->flextype -> container ( ' yaml ' ) ->encode ([
130143 'title ' => $ post_data ['title ' ],
131144 'icon ' => $ post_data ['icon ' ],
132145 'limit_calls ' => (int ) $ post_data ['limit_calls ' ],
@@ -139,18 +152,18 @@ public function addProcess(Request $request, Response $response) : Response
139152 'updated_at ' => $ time ,
140153 ])
141154 )) {
142- $ this ->flash ->addMessage ('success ' , __ ('admin_message_access_api_token_created ' ));
155+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('success ' , __ ('admin_message_access_api_token_created ' ));
143156 } else {
144- $ this ->flash ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_created1 ' ));
157+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_created1 ' ));
145158 }
146159 } else {
147- $ this ->flash ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_created2 ' ));
160+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_created2 ' ));
148161 }
149162
150163 if (isset ($ post_data ['create-and-edit ' ])) {
151- return $ response ->withRedirect ($ this ->router ->pathFor ('admin.api_access.edit ' ) . '?token= ' . $ api_token );
164+ return $ response ->withRedirect ($ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.edit ' ) . '?token= ' . $ api_token );
152165 } else {
153- return $ response ->withRedirect ($ this ->router ->pathFor ('admin.api_access.index ' ));
166+ return $ response ->withRedirect ($ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ));
154167 }
155168 }
156169
@@ -163,9 +176,9 @@ public function addProcess(Request $request, Response $response) : Response
163176 public function edit (Request $ request , Response $ response ) : Response
164177 {
165178 $ token = $ request ->getQueryParams ()['token ' ];
166- $ token_data = $ this ->yaml ->decode (Filesystem::read (PATH ['project ' ] . '/tokens ' . '/access/ ' . $ token . '/token.yaml ' ));
179+ $ token_data = $ this ->flextype -> container ( ' yaml ' ) ->decode (Filesystem::read (PATH ['project ' ] . '/tokens ' . '/access/ ' . $ token . '/token.yaml ' ));
167180
168- return $ this ->twig ->render (
181+ return $ this ->flextype -> container ( ' twig ' ) ->render (
169182 $ response ,
170183 'plugins/admin/templates/system/api/access/edit.html ' ,
171184 [
@@ -174,15 +187,15 @@ public function edit(Request $request, Response $response) : Response
174187 'token_data ' => $ token_data ,
175188 'links ' => [
176189 'api ' => [
177- 'link ' => $ this ->router ->pathFor ('admin.api.index ' ),
190+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api.index ' ),
178191 'title ' => __ ('admin_api ' )
179192 ],
180193 'api_access ' => [
181- 'link ' => $ this ->router ->pathFor ('admin.api_access.index ' ),
194+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ),
182195 'title ' => __ ('admin_access ' )
183196 ],
184197 'api_tokens_edit ' => [
185- 'link ' => $ this ->router ->pathFor ('admin.api_access.edit ' ),
198+ 'link ' => $ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.edit ' ),
186199 'title ' => __ ('admin_edit_token ' ),
187200 'active ' => true
188201 ],
@@ -209,7 +222,7 @@ public function editProcess(Request $request, Response $response) : Response
209222 if (Filesystem::has ($ api_token_file_path )) {
210223 if (Filesystem::write (
211224 $ api_token_file_path ,
212- $ this ->yaml ->encode ([
225+ $ this ->flextype -> container ( ' yaml ' ) ->encode ([
213226 'title ' => $ post_data ['title ' ],
214227 'icon ' => $ post_data ['icon ' ],
215228 'limit_calls ' => (int ) $ post_data ['limit_calls ' ],
@@ -219,16 +232,16 @@ public function editProcess(Request $request, Response $response) : Response
219232 'created_by ' => $ post_data ['created_by ' ],
220233 'created_at ' => $ post_data ['created_at ' ],
221234 'updated_by ' => Session::get ('uuid ' ),
222- 'updated_at ' => date ($ this ->registry ->get ('flextype.settings.date_format ' ), time ()),
235+ 'updated_at ' => date ($ this ->flextype -> container ( ' registry ' ) ->get ('flextype.settings.date_format ' ), time ()),
223236 ])
224237 )) {
225- $ this ->flash ->addMessage ('success ' , __ ('admin_message_access_api_token_updated ' ));
238+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('success ' , __ ('admin_message_access_api_token_updated ' ));
226239 }
227240 } else {
228- $ this ->flash ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_updated ' ));
241+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_updated ' ));
229242 }
230243
231- return $ response ->withRedirect ($ this ->router ->pathFor ('admin.api_access.index ' ));
244+ return $ response ->withRedirect ($ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ));
232245 }
233246
234247 /**
@@ -245,11 +258,11 @@ public function deleteProcess(Request $request, Response $response) : Response
245258 $ api_token_dir_path = PATH ['project ' ] . '/tokens ' . '/access/ ' . $ post_data ['token ' ];
246259
247260 if (Filesystem::deleteDir ($ api_token_dir_path )) {
248- $ this ->flash ->addMessage ('success ' , __ ('admin_message_access_api_token_deleted ' ));
261+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('success ' , __ ('admin_message_access_api_token_deleted ' ));
249262 } else {
250- $ this ->flash ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_deleted ' ));
263+ $ this ->flextype -> container ( ' flash ' ) ->addMessage ('error ' , __ ('admin_message_access_api_token_was_not_deleted ' ));
251264 }
252265
253- return $ response ->withRedirect ($ this ->router ->pathFor ('admin.api_access.index ' ));
266+ return $ response ->withRedirect ($ this ->flextype -> container ( ' router ' ) ->pathFor ('admin.api_access.index ' ));
254267 }
255268}
0 commit comments