Passed
Push — master ( cbe288...130872 )
by Peter
02:31
created

admin-routes.php (3 issues)

Labels
Severity
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 Opulence\Routing\Router;
10
11
/**
12
 * ----------------------------------------------------------
13
 * Create all of the routes for the HTTP kernel
14
 * ----------------------------------------------------------
15
 *
16
 * @var Router $router
17
 */
18
$router->group(
19
    ['controllerNamespace' => 'AbterPhp\Website\Http\Controllers'],
20
    function (Router $router) {
21
        $router->group(
22
            [
23
                '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...
24
                'middleware' => [
25
                    Authentication::class,
26
                ],
27
            ],
28
            function (Router $router) {
29
                $entities = [
30
                    'pages'          => 'Page',
31
                    'pagelayouts'    => 'PageLayout',
32
                    'pagecategories' => 'PageCategory',
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
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Grid\PageLayout::show() */
44
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Grid\PageCategory::show() */
45
                    $router->get(
46
                        "/${path}",
47
                        "Admin\Grid\\${controllerName}@show",
48
                        [
49
                            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...
50
                            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...
51
                                Authorization::withParameters(
52
                                    [
53
                                        Authorization::RESOURCE => $route,
54
                                        Authorization::ROLE     => Role::READ,
55
                                    ]
56
                                ),
57
                                LastGridPage::class,
58
                            ],
59
                        ]
60
                    );
61
62
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::new() */
63
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::new() */
64
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::new() */
65
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::new() */
66
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageCategory::new() */
67
                    $router->get(
68
                        "/${path}/new",
69
                        "Admin\Form\\${controllerName}@new",
70
                        [
71
                            OPTION_NAME       => "${route}-new",
72
                            OPTION_MIDDLEWARE => [
73
                                Authorization::withParameters(
74
                                    [
75
                                        Authorization::RESOURCE => $route,
76
                                        Authorization::ROLE     => Role::WRITE,
77
                                    ]
78
                                ),
79
                            ],
80
                        ]
81
                    );
82
83
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::create() */
84
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::create() */
85
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::create() */
86
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::create() */
87
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageCategory::create() */
88
                    $router->post(
89
                        "/${path}/new",
90
                        "Admin\Execute\\${controllerName}@create",
91
                        [
92
                            OPTION_NAME       => "${route}-create",
93
                            OPTION_MIDDLEWARE => [
94
                                Authorization::withParameters(
95
                                    [
96
                                        Authorization::RESOURCE => $route,
97
                                        Authorization::ROLE     => Role::WRITE,
98
                                    ]
99
                                ),
100
                            ],
101
                        ]
102
                    );
103
104
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Block::edit() */
105
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::edit() */
106
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\Page::edit() */
107
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageLayout::edit() */
108
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Form\PageCategory::edit() */
109
                    $router->get(
110
                        "/${path}/:entityId/edit",
111
                        "Admin\Form\\${controllerName}@edit",
112
                        [
113
                            OPTION_NAME       => "${route}-edit",
114
                            OPTION_MIDDLEWARE => [
115
                                Authorization::withParameters(
116
                                    [
117
                                        Authorization::RESOURCE => $route,
118
                                        Authorization::ROLE     => Role::WRITE,
119
                                    ]
120
                                ),
121
                            ],
122
                        ]
123
                    );
124
125
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Block::update() */
126
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\BlockLayout::update() */
127
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Page::update() */
128
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\PageLayout::update() */
129
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\PageCategory::update() */
130
                    $router->put(
131
                        "/${path}/:entityId/edit",
132
                        "Admin\Execute\\${controllerName}@update",
133
                        [
134
                            OPTION_NAME       => "${route}-update",
135
                            OPTION_MIDDLEWARE => [
136
                                Authorization::withParameters(
137
                                    [
138
                                        Authorization::RESOURCE => $route,
139
                                        Authorization::ROLE     => Role::WRITE,
140
                                    ]
141
                                ),
142
                            ],
143
                        ]
144
                    );
145
146
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Block::delete() */
147
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\BlockLayout::delete() */
148
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\Page::delete() */
149
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\PageLayout::delete() */
150
                    /** @see \AbterPhp\Website\Http\Controllers\Admin\Execute\PageCategory::delete() */
151
                    $router->get(
152
                        "/${path}/:entityId/delete",
153
                        "Admin\Execute\\${controllerName}@delete",
154
                        [
155
                            OPTION_NAME       => "${route}-delete",
156
                            OPTION_MIDDLEWARE => [
157
                                Authorization::withParameters(
158
                                    [
159
                                        Authorization::RESOURCE => $route,
160
                                        Authorization::ROLE     => Role::WRITE,
161
                                    ]
162
                                ),
163
                            ],
164
                        ]
165
                    );
166
                }
167
            }
168
        );
169
    }
170
);
171