Passed
Push — master ( d5b3dd...46d4e1 )
by Peter
15:19 queued 12:52
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\Contact\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
                    'contactforms' => 'ContactForm',
31
                ];
32
33
                foreach ($entities as $route => $controllerName) {
34
                    $path = strtolower($controllerName);
35
36
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Grid\ContactForm::show() */
37
                    $router->get(
38
                        "/${path}",
39
                        "Admin\Grid\\${controllerName}@show",
40
                        [
41
                            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...
42
                            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...
43
                                Authorization::withParameters(
44
                                    [
45
                                        Authorization::RESOURCE => $route,
46
                                        Authorization::ROLE     => Role::READ,
47
                                    ]
48
                                ),
49
                                LastGridPage::class,
50
                            ],
51
                        ]
52
                    );
53
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Form\ContactForm::new() */
54
                    $router->get(
55
                        "/${path}/new",
56
                        "Admin\Form\\${controllerName}@new",
57
                        [
58
                            OPTION_NAME       => "${route}-new",
59
                            OPTION_MIDDLEWARE => [
60
                                Authorization::withParameters(
61
                                    [
62
                                        Authorization::RESOURCE => $route,
63
                                        Authorization::ROLE     => Role::WRITE,
64
                                    ]
65
                                ),
66
                            ],
67
                        ]
68
                    );
69
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Execute\ContactForm::create() */
70
                    $router->post(
71
                        "/${path}/new",
72
                        "Admin\Execute\\${controllerName}@create",
73
                        [
74
                            OPTION_NAME       => "${route}-create",
75
                            OPTION_MIDDLEWARE => [
76
                                Authorization::withParameters(
77
                                    [
78
                                        Authorization::RESOURCE => $route,
79
                                        Authorization::ROLE     => Role::WRITE,
80
                                    ]
81
                                ),
82
                            ],
83
                        ]
84
                    );
85
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Form\ContactForm::edit() */
86
                    $router->get(
87
                        "/${path}/:entityId/edit",
88
                        "Admin\Form\\${controllerName}@edit",
89
                        [
90
                            OPTION_NAME       => "${route}-edit",
91
                            OPTION_MIDDLEWARE => [
92
                                Authorization::withParameters(
93
                                    [
94
                                        Authorization::RESOURCE => $route,
95
                                        Authorization::ROLE     => Role::WRITE,
96
                                    ]
97
                                ),
98
                            ],
99
                        ]
100
                    );
101
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Execute\ContactForm::update() */
102
                    $router->put(
103
                        "/${path}/:entityId/edit",
104
                        "Admin\Execute\\${controllerName}@update",
105
                        [
106
                            OPTION_NAME       => "${route}-update",
107
                            OPTION_MIDDLEWARE => [
108
                                Authorization::withParameters(
109
                                    [
110
                                        Authorization::RESOURCE => $route,
111
                                        Authorization::ROLE     => Role::WRITE,
112
                                    ]
113
                                ),
114
                            ],
115
                        ]
116
                    );
117
                    /** @see \AbterPhp\Contact\Http\Controllers\Admin\Execute\ContactForm::delete() */
118
                    $router->get(
119
                        "/${path}/:entityId/delete",
120
                        "Admin\Execute\\${controllerName}@delete",
121
                        [
122
                            OPTION_NAME       => "${route}-delete",
123
                            OPTION_MIDDLEWARE => [
124
                                Authorization::withParameters(
125
                                    [
126
                                        Authorization::RESOURCE => $route,
127
                                        Authorization::ROLE     => Role::WRITE,
128
                                    ]
129
                                ),
130
                            ],
131
                        ]
132
                    );
133
                }
134
            }
135
        );
136
    }
137
);
138