Passed
Push — master ( f85738...3d85c1 )
by Peter
04:52
created

admin-routes.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
use AbterPhp\Admin\Constant\Routes;
6
use AbterPhp\Admin\Http\Middleware\Authentication;
7
use AbterPhp\Admin\Http\Middleware\Authorization;
8
use AbterPhp\Admin\Http\Middleware\LastGridPage;
9
use AbterPhp\Framework\Authorization\Constant\Role;
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\Admin\\Http\\Controllers'],
21
    function (Router $router) {
22
        $router->group(
23
            [
24
                'path'       => PATH_ADMIN,
0 ignored issues
show
The constant PATH_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
                'middleware' => [
26
                    Authentication::class,
27
                ],
28
            ],
29
            function (Router $router) {
30
                $entities = [
31
                    'usergroups' => 'UserGroup',
32
                    'users'      => 'User',
33
                    'apiclients' => 'ApiClient',
34
                ];
35
36
                foreach ($entities as $route => $controllerName) {
37
                    $path = strtolower($controllerName);
38
39
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Grid\User::show() */
40
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Grid\UserGroup::show() */
41
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Grid\ApiClient::show() */
42
                    $router->get(
43
                        "/${path}",
44
                        "Admin\Grid\\${controllerName}@show",
45
                        [
46
                            OPTION_NAME       => "${route}",
0 ignored issues
show
The constant OPTION_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
                            OPTION_MIDDLEWARE => [
0 ignored issues
show
The constant OPTION_MIDDLEWARE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
48
                                Authorization::withParameters(
49
                                    [
50
                                        Authorization::RESOURCE => $route,
51
                                        Authorization::ROLE     => Role::READ,
52
                                    ]
53
                                ),
54
                                LastGridPage::class,
55
                            ],
56
                        ]
57
                    );
58
59
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\User::new() */
60
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\UserGroup::new() */
61
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\ApiClient::new() */
62
                    $router->get(
63
                        "/${path}/new",
64
                        "Admin\Form\\${controllerName}@new",
65
                        [
66
                            OPTION_NAME       => "${route}-new",
67
                            OPTION_MIDDLEWARE => [
68
                                Authorization::withParameters(
69
                                    [
70
                                        Authorization::RESOURCE => $route,
71
                                        Authorization::ROLE     => Role::WRITE,
72
                                    ]
73
                                ),
74
                            ],
75
                        ]
76
                    );
77
78
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\User::create() */
79
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\UserGroup::create() */
80
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\ApiClient::create() */
81
                    $router->post(
82
                        "/${path}/new",
83
                        "Admin\Execute\\${controllerName}@create",
84
                        [
85
                            OPTION_NAME       => "${route}-create",
86
                            OPTION_MIDDLEWARE => [
87
                                Authorization::withParameters(
88
                                    [
89
                                        Authorization::RESOURCE => $route,
90
                                        Authorization::ROLE     => Role::WRITE,
91
                                    ]
92
                                ),
93
                            ],
94
                        ]
95
                    );
96
97
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\User::edit() */
98
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\UserGroup::edit() */
99
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\ApiClient::edit() */
100
                    $router->get(
101
                        "/${path}/:entityId/edit",
102
                        "Admin\Form\\${controllerName}@edit",
103
                        [
104
                            OPTION_NAME       => "${route}-edit",
105
                            OPTION_MIDDLEWARE => [
106
                                Authorization::withParameters(
107
                                    [
108
                                        Authorization::RESOURCE => $route,
109
                                        Authorization::ROLE     => Role::WRITE,
110
                                    ]
111
                                ),
112
                            ],
113
                        ]
114
                    );
115
116
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\User::update() */
117
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\UserGroup::update() */
118
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\ApiClient::update() */
119
                    $router->put(
120
                        "/${path}/:entityId/edit",
121
                        "Admin\Execute\\${controllerName}@update",
122
                        [
123
                            OPTION_NAME       => "${route}-update",
124
                            OPTION_MIDDLEWARE => [
125
                                Authorization::withParameters(
126
                                    [
127
                                        Authorization::RESOURCE => $route,
128
                                        Authorization::ROLE     => Role::WRITE,
129
                                    ]
130
                                ),
131
                            ],
132
                        ]
133
                    );
134
135
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\User::delete() */
136
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\UserGroup::delete() */
137
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\ApiClient::delete() */
138
                    $router->get(
139
                        "/${path}/:entityId/delete",
140
                        "Admin\Execute\\${controllerName}@delete",
141
                        [
142
                            OPTION_NAME       => "${route}-delete",
143
                            OPTION_MIDDLEWARE => [
144
                                Authorization::withParameters(
145
                                    [
146
                                        Authorization::RESOURCE => $route,
147
                                        Authorization::ROLE     => Role::WRITE,
148
                                    ]
149
                                ),
150
                            ],
151
                        ]
152
                    );
153
                }
154
155
                /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\Profile::profile() */
156
                $router->get(
157
                    Routes::PATH_PROFILE,
158
                    'Admin\Form\Profile@profile',
159
                    [
160
                        OPTION_NAME => Routes::ROUTE_PROFILE,
161
                    ]
162
                );
163
164
                /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\Profile::execute() */
165
                $router->put(
166
                    Routes::PATH_PROFILE,
167
                    'Admin\Execute\Profile@profile',
168
                    [
169
                        OPTION_NAME => Routes::ROUTE_PROFILE,
170
                    ]
171
                );
172
173
                /** @see \AbterPhp\Admin\Http\Controllers\Admin\Dashboard::showDashboard() */
174
                $router->get(
175
                    Routes::PATH_DASHBOARD,
176
                    'Admin\Dashboard@showDashboard',
177
                    [
178
                        OPTION_NAME => Routes::ROUTE_DASHBOARD,
179
                    ]
180
                );
181
            }
182
        );
183
    }
184
);
185