1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | use AbterPhp\Admin\Http\Middleware\Authentication; |
||
6 | use AbterPhp\Admin\Http\Middleware\Authorization; |
||
7 | use AbterPhp\Admin\Http\Middleware\LastGridPage; |
||
8 | use AbterPhp\Framework\Authorization\Constant\Role; |
||
9 | use AbterPhp\Website\Constant\Routes; |
||
10 | use Opulence\Routing\Router; |
||
11 | |||
12 | /** |
||
13 | * ---------------------------------------------------------- |
||
14 | * Create all of the routes for the HTTP kernel |
||
15 | * ---------------------------------------------------------- |
||
16 | * |
||
17 | * @var Router $router |
||
18 | */ |
||
19 | $router->group( |
||
20 | ['controllerNamespace' => 'AbterPhp\Website\Http\Controllers'], |
||
21 | function (Router $router) { |
||
22 | $router->group( |
||
23 | [ |
||
24 | 'path' => PATH_ADMIN, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | 'middleware' => [ |
||
26 | Authentication::class, |
||
27 | ], |
||
28 | ], |
||
29 | function (Router $router) { |
||
30 | $entities = [ |
||
31 | 'pages' => 'Page', |
||
32 | 'pagelayouts' => 'PageLayout', |
||
33 | 'blocks' => 'Block', |
||
34 | 'blocklayouts' => 'BlockLayout', |
||
35 | ]; |
||
36 | |||
37 | foreach ($entities as $route => $controllerName) { |
||
38 | $path = strtolower($controllerName); |
||
39 | |||
40 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Grid\Block::show() */ |
||
41 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Grid\BlockLayout::show() */ |
||
42 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Grid\Page::show() */ |
||
43 | $router->get( |
||
44 | "/${path}", |
||
45 | "Admin\Grid\\${controllerName}@show", |
||
46 | [ |
||
47 | OPTION_NAME => "${route}", |
||
0 ignored issues
–
show
|
|||
48 | OPTION_MIDDLEWARE => [ |
||
0 ignored issues
–
show
|
|||
49 | Authorization::withParameters( |
||
50 | [ |
||
51 | Authorization::RESOURCE => $route, |
||
52 | Authorization::ROLE => Role::READ, |
||
53 | ] |
||
54 | ), |
||
55 | LastGridPage::class, |
||
56 | ], |
||
57 | ] |
||
58 | ); |
||
59 | |||
60 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::new() */ |
||
61 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::new() */ |
||
62 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::new() */ |
||
63 | $router->get( |
||
64 | "/${path}/new", |
||
65 | "Admin\Form\\${controllerName}@new", |
||
66 | [ |
||
67 | OPTION_NAME => "${route}-new", |
||
68 | OPTION_MIDDLEWARE => [ |
||
69 | Authorization::withParameters( |
||
70 | [ |
||
71 | Authorization::RESOURCE => $route, |
||
72 | Authorization::ROLE => Role::WRITE, |
||
73 | ] |
||
74 | ), |
||
75 | ], |
||
76 | ] |
||
77 | ); |
||
78 | |||
79 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::create() */ |
||
80 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::create() */ |
||
81 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::create() */ |
||
82 | $router->post( |
||
83 | "/${path}/new", |
||
84 | "Admin\Execute\\${controllerName}@create", |
||
85 | [ |
||
86 | OPTION_NAME => "${route}-create", |
||
87 | OPTION_MIDDLEWARE => [ |
||
88 | Authorization::withParameters( |
||
89 | [ |
||
90 | Authorization::RESOURCE => $route, |
||
91 | Authorization::ROLE => Role::WRITE, |
||
92 | ] |
||
93 | ), |
||
94 | ], |
||
95 | ] |
||
96 | ); |
||
97 | |||
98 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::edit() */ |
||
99 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::edit() */ |
||
100 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::edit() */ |
||
101 | $router->get( |
||
102 | "/${path}/:entityId/edit", |
||
103 | "Admin\Form\\${controllerName}@edit", |
||
104 | [ |
||
105 | OPTION_NAME => "${route}-edit", |
||
106 | OPTION_MIDDLEWARE => [ |
||
107 | Authorization::withParameters( |
||
108 | [ |
||
109 | Authorization::RESOURCE => $route, |
||
110 | Authorization::ROLE => Role::WRITE, |
||
111 | ] |
||
112 | ), |
||
113 | ], |
||
114 | ] |
||
115 | ); |
||
116 | |||
117 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Block::update() */ |
||
118 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\BlockLayout::update() */ |
||
119 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Page::update() */ |
||
120 | $router->put( |
||
121 | "/${path}/:entityId/edit", |
||
122 | "Admin\Execute\\${controllerName}@update", |
||
123 | [ |
||
124 | OPTION_NAME => "${route}-update", |
||
125 | OPTION_MIDDLEWARE => [ |
||
126 | Authorization::withParameters( |
||
127 | [ |
||
128 | Authorization::RESOURCE => $route, |
||
129 | Authorization::ROLE => Role::WRITE, |
||
130 | ] |
||
131 | ), |
||
132 | ], |
||
133 | ] |
||
134 | ); |
||
135 | |||
136 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Block::delete() */ |
||
137 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\BlockLayout::delete() */ |
||
138 | /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Page::delete() */ |
||
139 | $router->get( |
||
140 | "/${path}/:entityId/delete", |
||
141 | "Admin\Execute\\${controllerName}@delete", |
||
142 | [ |
||
143 | OPTION_NAME => "${route}-delete", |
||
144 | OPTION_MIDDLEWARE => [ |
||
145 | Authorization::withParameters( |
||
146 | [ |
||
147 | Authorization::RESOURCE => $route, |
||
148 | Authorization::ROLE => Role::WRITE, |
||
149 | ] |
||
150 | ), |
||
151 | ], |
||
152 | ] |
||
153 | ); |
||
154 | } |
||
155 | } |
||
156 | ); |
||
157 | } |
||
158 | ); |
||
159 |