Passed
Push — master ( 9356d0...6648b6 )
by Peter
02:13
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
                ];
34
35
                foreach ($entities as $route => $controllerName) {
36
                    $path = strtolower($controllerName);
37
38
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Grid\User::show() */
39
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Grid\UserGroup::show() */
40
                    $router->get(
41
                        "/${path}",
42
                        "Admin\Grid\\${controllerName}@show",
43
                        [
44
                            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...
45
                            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...
46
                                Authorization::withParameters(
47
                                    [
48
                                        Authorization::RESOURCE => $route,
49
                                        Authorization::ROLE     => Role::READ,
50
                                    ]
51
                                ),
52
                                LastGridPage::class,
53
                            ],
54
                        ]
55
                    );
56
57
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\User::new() */
58
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\UserGroup::new() */
59
                    $router->get(
60
                        "/${path}/new",
61
                        "Admin\Form\\${controllerName}@new",
62
                        [
63
                            OPTION_NAME       => "${route}-new",
64
                            OPTION_MIDDLEWARE => [
65
                                Authorization::withParameters(
66
                                    [
67
                                        Authorization::RESOURCE => $route,
68
                                        Authorization::ROLE     => Role::WRITE,
69
                                    ]
70
                                ),
71
                            ],
72
                        ]
73
                    );
74
75
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\User::create() */
76
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\UserGroup::create() */
77
                    $router->post(
78
                        "/${path}/new",
79
                        "Admin\Execute\\${controllerName}@create",
80
                        [
81
                            OPTION_NAME       => "${route}-create",
82
                            OPTION_MIDDLEWARE => [
83
                                Authorization::withParameters(
84
                                    [
85
                                        Authorization::RESOURCE => $route,
86
                                        Authorization::ROLE     => Role::WRITE,
87
                                    ]
88
                                ),
89
                            ],
90
                        ]
91
                    );
92
93
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\User::edit() */
94
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Form\UserGroup::edit() */
95
                    $router->get(
96
                        "/${path}/:entityId/edit",
97
                        "Admin\Form\\${controllerName}@edit",
98
                        [
99
                            OPTION_NAME       => "${route}-edit",
100
                            OPTION_MIDDLEWARE => [
101
                                Authorization::withParameters(
102
                                    [
103
                                        Authorization::RESOURCE => $route,
104
                                        Authorization::ROLE     => Role::WRITE,
105
                                    ]
106
                                ),
107
                            ],
108
                        ]
109
                    );
110
111
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\User::update() */
112
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\UserGroup::update() */
113
                    $router->put(
114
                        "/${path}/:entityId/edit",
115
                        "Admin\Execute\\${controllerName}@update",
116
                        [
117
                            OPTION_NAME       => "${route}-update",
118
                            OPTION_MIDDLEWARE => [
119
                                Authorization::withParameters(
120
                                    [
121
                                        Authorization::RESOURCE => $route,
122
                                        Authorization::ROLE     => Role::WRITE,
123
                                    ]
124
                                ),
125
                            ],
126
                        ]
127
                    );
128
129
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\User::delete() */
130
                    /** @see \AbterPhp\Admin\Http\Controllers\Admin\Execute\UserGroup::delete() */
131
                    $router->get(
132
                        "/${path}/:entityId/delete",
133
                        "Admin\Execute\\${controllerName}@delete",
134
                        [
135
                            OPTION_NAME       => "${route}-delete",
136
                            OPTION_MIDDLEWARE => [
137
                                Authorization::withParameters(
138
                                    [
139
                                        Authorization::RESOURCE => $route,
140
                                        Authorization::ROLE     => Role::WRITE,
141
                                    ]
142
                                ),
143
                            ],
144
                        ]
145
                    );
146
                }
147
148
                /** @see \AbterPhp\Admin\Http\Controllers\Admin\Dashboard::showDashboard() */
149
                $router->get(
150
                    Routes::PATH_DASHBOARD,
151
                    'Admin\Dashboard@showDashboard',
152
                    [
153
                        OPTION_NAME => Routes::ROUTE_DASHBOARD,
154
                    ]
155
                );
156
            }
157
        );
158
    }
159
);
160