1 | <?php |
||
2 | |||
3 | use App\Rest\Router as RestRouter; |
||
4 | |||
5 | $router = new RestRouter($container['router'], $container['settings']['rest']); |
||
6 | |||
7 | /** |
||
8 | * CORS Pre-flight request. |
||
9 | */ |
||
10 | $app->options('/{routes:.+}', function ($request, $response) { |
||
11 | return $response; |
||
12 | }); |
||
13 | |||
14 | /** |
||
15 | * Security. |
||
16 | */ |
||
17 | $app->group('/', function () use ($container) { |
||
18 | $this->post('register', 'registration.controller:register')->setName('register'); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
19 | $this->post('oauth/v2/token', 'token.controller:token')->setName('oauth_token'); |
||
20 | $this->get('user', 'token.controller:user') |
||
21 | ->add($container['auth.middleware']) |
||
22 | ->setName('user'); |
||
23 | }); |
||
24 | |||
25 | $app->get('/', 'app.controller:root')->setName('root'); |
||
26 | |||
27 | /** |
||
28 | * URL | CONTROLLER | ROUTE |
||
29 | * ---------------------|---------------------------------|---------------- |
||
30 | * GET /articles | article.controller:getArticle | get_articles |
||
31 | * GET /articles/{id} | article.controller:getArticles | get_article |
||
32 | * POST /articles | article.controller:postArticle | post_article |
||
33 | * PUT /articles/{id} | article.controller:putArticle | put_article |
||
34 | * DELETE /article/{id} | article.controller:deleteArticle | delete_article |
||
35 | */ |
||
36 | $router->crud('articles', 'article.controller'); |
||
37 | |||
38 | // OR |
||
39 | |||
40 | /** |
||
41 | * $router->cget('articles', 'article.controller'); |
||
42 | * $router->get('articles', 'article.controller'); |
||
43 | * $router->post('articles', 'article.controller'); |
||
44 | * $router->put('articles', 'article.controller'); |
||
45 | * $router->delete('articles', 'article.controller'); |
||
46 | */ |
||
47 | |||
48 | // With options |
||
49 | /** |
||
50 | * $options = [ |
||
51 | * 'key' => 'id', |
||
52 | * 'requirement' => '[0-9]+', |
||
53 | * 'singular' => 'article' |
||
54 | * ]; |
||
55 | * |
||
56 | * $router->crud('articles', 'article.controller', [], $options); |
||
57 | * |
||
58 | * OR |
||
59 | * |
||
60 | * $router->get('articles', 'article.controller', $options); |
||
61 | * ... |
||
62 | */ |
||
63 | |||
64 | /***********************************************************/ |
||
65 | /* -------------------- SUB RESOURCES -------------------- */ |
||
66 | /***********************************************************/ |
||
67 | |||
68 | /** |
||
69 | * URL | CONTROLLER | ROUTE |
||
70 | * ---------------------------------------------------|-----------------------------------------------|------------------------ |
||
71 | * GET /articles/{article_id}/comments | article.comment.controller:getArticleComments | get_article_comments |
||
72 | * GET /articles/{article_id}/comments/{comment_id} | article.comment.controller:getArticleComment | get_article_comment |
||
73 | * POST /articles/{article_id}/comments | article.comment.controller:postArticleComment | post_article_comment |
||
74 | * PUT /articles/{article_id}/comments/{comment_id} | article.comment.controller:putArticleComment | put_article_comment |
||
75 | * DELETE /article/{article_id}/comments/{comment_id} | article.comment.controller:deleteArticleComment | delete_article_comment |
||
76 | */ |
||
77 | $router->subCrud('articles', 'comments', 'article.comment.controller'); |
||
78 | |||
79 | // OR |
||
80 | |||
81 | /** |
||
82 | * $router->cgetSub('articles', 'comments', 'article.controller'); |
||
83 | * $router->getSub('articles', 'comments', 'article.controller'); |
||
84 | * $router->postSub('articles', 'comments', 'article.controller'); |
||
85 | * $router->putSub('articles', 'comments', 'article.controller'); |
||
86 | * $router->deleteSub('articles', 'comments', 'article.controller'); |
||
87 | */ |
||
88 | |||
89 | // With options |
||
90 | /** |
||
91 | * $options = [ |
||
92 | * 'parent_key' => 'article_id', |
||
93 | * 'parent_requirement' => '[0-9]+', |
||
94 | * 'sub_key' => 'comment_id', |
||
95 | * 'sub_requirement' => '[0-9]+', |
||
96 | * 'parent_singular' => 'article', |
||
97 | * 'sub_singular' => 'comment' |
||
98 | * ]; |
||
99 | * |
||
100 | * $router->subCrud('articles', 'comments', 'article.comment.controller', [], $options); |
||
101 | * |
||
102 | * OR |
||
103 | * |
||
104 | * $router->getSub('articles', 'comments', 'article.controller', $options); |
||
105 | * ... |
||
106 | */ |
||
107 |