Passed
Push — master ( 335667...411407 )
by Peter
02:16
created

admin-routes.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
use AbterPhp\Admin\Http\Middleware\Api;
6
use AbterPhp\Admin\Http\Middleware\Authentication;
7
use AbterPhp\Admin\Http\Middleware\Authorization;
8
use AbterPhp\Admin\Http\Middleware\LastGridPage;
9
use AbterPhp\Files\Constant\Routes;
10
use AbterPhp\Framework\Authorization\Constant\Role;
11
use Opulence\Routing\Router;
12
13
/**
14
 * ----------------------------------------------------------
15
 * Create all of the routes for the HTTP kernel
16
 * ----------------------------------------------------------
17
 *
18
 * @var Router $router
19
 */
20
$router->group(
21
    ['controllerNamespace' => 'AbterPhp\Files\Http\Controllers'],
22
    function (Router $router) {
23
        $router->group(
24
            [
25
                '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...
26
                'middleware' => [
27
                    Authentication::class,
28
                ],
29
            ],
30
            function (Router $router) {
31
                $entities = [
32
                    'filecategories' => 'FileCategory',
33
                    'filedownloads'  => 'FileDownload',
34
                    'files'          => 'File',
35
                ];
36
37
                foreach ($entities as $route => $controllerName) {
38
                    $path = strtolower($controllerName);
39
40
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Grid\File::show() */
41
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Grid\FileCategory::show() */
42
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Grid\FileDownload::show() */
43
                    $router->get(
44
                        "/${path}",
45
                        "Admin\Grid\\${controllerName}@show",
46
                        [
47
                            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...
48
                            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...
49
                                Authorization::withParameters(
50
                                    [
51
                                        Authorization::RESOURCE => $route,
52
                                        Authorization::ROLE     => Role::READ,
53
                                    ]
54
                                ),
55
                                LastGridPage::class,
56
                            ],
57
                        ]
58
                    );
59
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\File::new() */
60
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\FileCategory::new() */
61
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\FileDownload::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
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\File::create() */
78
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileCategory::create() */
79
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileDownload::create() */
80
                    $router->post(
81
                        "/${path}/new",
82
                        "Admin\Execute\\${controllerName}@create",
83
                        [
84
                            OPTION_NAME       => "${route}-create",
85
                            OPTION_MIDDLEWARE => [
86
                                Authorization::withParameters(
87
                                    [
88
                                        Authorization::RESOURCE => $route,
89
                                        Authorization::ROLE     => Role::WRITE,
90
                                    ]
91
                                ),
92
                            ],
93
                        ]
94
                    );
95
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\File::edit() */
96
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\FileCategory::edit() */
97
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Form\FileDownload::edit() */
98
                    $router->get(
99
                        "/${path}/:entityId/edit",
100
                        "Admin\Form\\${controllerName}@edit",
101
                        [
102
                            OPTION_NAME       => "${route}-edit",
103
                            OPTION_MIDDLEWARE => [
104
                                Authorization::withParameters(
105
                                    [
106
                                        Authorization::RESOURCE => $route,
107
                                        Authorization::ROLE     => Role::WRITE,
108
                                    ]
109
                                ),
110
                            ],
111
                        ]
112
                    );
113
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\File::update() */
114
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileCategory::update() */
115
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileDownload::update() */
116
                    $router->put(
117
                        "/${path}/:entityId/edit",
118
                        "Admin\Execute\\${controllerName}@update",
119
                        [
120
                            OPTION_NAME       => "${route}-update",
121
                            OPTION_MIDDLEWARE => [
122
                                Authorization::withParameters(
123
                                    [
124
                                        Authorization::RESOURCE => $route,
125
                                        Authorization::ROLE     => Role::WRITE,
126
                                    ]
127
                                ),
128
                            ],
129
                        ]
130
                    );
131
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\File::delete() */
132
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileCategory::delete() */
133
                    /** @see \AbterPhp\Files\Http\Controllers\Admin\Execute\FileDownload::delete() */
134
                    $router->get(
135
                        "/${path}/:entityId/delete",
136
                        "Admin\Execute\\${controllerName}@delete",
137
                        [
138
                            OPTION_NAME       => "${route}-delete",
139
                            OPTION_MIDDLEWARE => [
140
                                Authorization::withParameters(
141
                                    [
142
                                        Authorization::RESOURCE => $route,
143
                                        Authorization::ROLE     => Role::WRITE,
144
                                    ]
145
                                ),
146
                            ],
147
                        ]
148
                    );
149
                }
150
151
                /** @see \AbterPhp\Files\Http\Controllers\Api\File\Download::download() */
152
                $router->get(
153
                    Routes::PATH_API_DOWNLOAD,
154
                    'Api\File\Download@download',
155
                    [
156
                        OPTION_NAME       => Routes::ROUTE_FILES_DOWNLOAD,
157
                        OPTION_MIDDLEWARE => [
158
                            Authorization::withParameters(
159
                                [
160
                                    Authorization::RESOURCE => 'files',
161
                                    Authorization::ROLE     => Role::READ,
162
                                ]
163
                            ),
164
                        ],
165
                    ]
166
                );
167
168
                /** @see \AbterPhp\Files\Http\Controllers\Api\File\Csv::csv() */
169
                $router->get(
170
                    Routes::PATH_API_DOWNLOAD,
171
                    'Api\File\Download@download',
172
                    [
173
                        OPTION_NAME       => Routes::ROUTE_FILES_DOWNLOAD,
174
                        OPTION_MIDDLEWARE => [
175
                            Authorization::withParameters(
176
                                [
177
                                    Authorization::RESOURCE => 'files',
178
                                    Authorization::ROLE     => Role::READ,
179
                                ]
180
                            ),
181
                        ],
182
                    ]
183
                );
184
            }
185
        );
186
    }
187
);
188