Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.26% |
143 / 155 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
AppRouteSetting | |
92.26% |
143 / 155 |
|
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
__construct | |
92.26% |
143 / 155 |
|
0.00% |
0 / 1 |
2.00 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models; |
6 | |
7 | use PeServer\App\Controllers\Api\AccountApiController; |
8 | use PeServer\App\Controllers\Api\AdministratorApiController; |
9 | use PeServer\App\Controllers\Api\ApplicationApiController; |
10 | use PeServer\App\Controllers\Api\DevelopmentApiController; |
11 | use PeServer\App\Controllers\Api\PluginApiController; |
12 | use PeServer\App\Controllers\Page\AccountController; |
13 | use PeServer\App\Controllers\Page\AjaxController; |
14 | use PeServer\App\Controllers\Page\HomeController; |
15 | use PeServer\App\Controllers\Page\ManagementControlController; |
16 | use PeServer\App\Controllers\Page\ManagementController; |
17 | use PeServer\App\Controllers\Page\PasswordController; |
18 | use PeServer\App\Controllers\Page\PluginController; |
19 | use PeServer\App\Controllers\Page\ToolController; |
20 | use PeServer\App\Models\Middleware\AccessLogMiddleware; |
21 | use PeServer\App\Models\Middleware\AdministratorAccountFilterMiddleware; |
22 | use PeServer\App\Models\Middleware\Api\ApiCorsMiddleware; |
23 | use PeServer\App\Models\Middleware\Api\ApiAdministratorAccountFilterMiddleware; |
24 | use PeServer\App\Models\Middleware\Api\ApiUserAccountFilterMiddleware; |
25 | use PeServer\App\Models\Middleware\DevelopmentMiddleware; |
26 | use PeServer\App\Models\Middleware\NotLoginMiddleware; |
27 | use PeServer\App\Models\Middleware\PluginIdMiddleware; |
28 | use PeServer\App\Models\Middleware\SetupAccountFilterMiddleware; |
29 | use PeServer\App\Models\Middleware\SignupStep2FilterMiddleware; |
30 | use PeServer\App\Models\Middleware\UserAccountFilterMiddleware; |
31 | use PeServer\App\Models\Middleware\UserPluginEditFilterMiddleware; |
32 | use PeServer\Core\Environment; |
33 | use PeServer\Core\Http\HttpMethod; |
34 | use PeServer\Core\Mvc\Middleware\CsrfMiddleware; |
35 | use PeServer\Core\Mvc\Middleware\HttpsMiddleware; |
36 | use PeServer\Core\Mvc\Middleware\PerformanceMiddleware; |
37 | use PeServer\Core\Mvc\Middleware\PerformanceShutdownMiddleware; |
38 | use PeServer\Core\Mvc\Route; |
39 | use PeServer\Core\Mvc\RouteSetting; |
40 | use PeServer\Core\Text; |
41 | |
42 | /** |
43 | * アプリルーティング設定。 |
44 | */ |
45 | final readonly class AppRouteSetting extends RouteSetting |
46 | { |
47 | private const SIGNUP_TOKEN = '[a-zA-Z0-9]{80}'; |
48 | private const PASSWORD_REMINDER_TOKEN = '[a-zA-Z0-9]{80}'; |
49 | private const PLUGIN_ID = '\{?[a-fA-F0-9\-]{32,}\}?'; |
50 | |
51 | public function __construct(Environment $environment) |
52 | { |
53 | $isProduction = $environment->isProduction(); |
54 | |
55 | $globalMiddleware = []; |
56 | $actionMiddleware = []; |
57 | $globalShutdownMiddleware = [ |
58 | AccessLogMiddleware::class, |
59 | ]; |
60 | $actionShutdownMiddleware = []; |
61 | |
62 | if ($isProduction) { |
63 | $globalMiddleware = [ |
64 | HttpsMiddleware::class, |
65 | ...$globalMiddleware, |
66 | ]; |
67 | |
68 | $actionMiddleware = [ |
69 | PerformanceMiddleware::class, |
70 | ...$actionMiddleware, |
71 | ]; |
72 | |
73 | $globalShutdownMiddleware = [ |
74 | PerformanceShutdownMiddleware::class, |
75 | ...$globalShutdownMiddleware, |
76 | ]; |
77 | } |
78 | |
79 | parent::__construct( |
80 | $globalMiddleware, |
81 | $actionMiddleware, |
82 | $globalShutdownMiddleware, |
83 | $actionShutdownMiddleware, |
84 | [ |
85 | (new Route(Text::EMPTY, HomeController::class)) |
86 | ->addAction('about', HttpMethod::gets(), 'about') |
87 | ->addAction('about/privacy', HttpMethod::gets(), 'privacy') |
88 | ->addAction('about/contact', HttpMethod::gets(), 'contact_get') |
89 | ->addAction('about/contact', HttpMethod::Post, 'contact_post') |
90 | ->addAction('api-doc', HttpMethod::gets(), 'api') |
91 | ->addAction('dev/exception', HttpMethod::gets(), 'exception', [DevelopmentMiddleware::class]) |
92 | ->addAction(':path@[a-zA-z0-9_\(\)\-]+\.[a-zA-z0-9_\(\)\-]+', HttpMethod::gets(), 'wildcard') |
93 | /* AUTO-FORMAT */, |
94 | (new Route('account', AccountController::class)) |
95 | ->addAction('login', HttpMethod::gets(), 'login_get') |
96 | ->addAction('login', HttpMethod::Post, 'login_post', [CsrfMiddleware::class]) |
97 | ->addAction('logout', HttpMethod::gets(), 'logout') |
98 | ->addAction('signup', HttpMethod::gets(), 'signup_step1_get', [NotLoginMiddleware::class]) |
99 | ->addAction('signup', HttpMethod::Post, 'signup_step1_post', [NotLoginMiddleware::class, CsrfMiddleware::class]) |
100 | ->addAction('signup/notify', HttpMethod::gets(), 'signup_notify', [NotLoginMiddleware::class]) |
101 | ->addAction('signup/:token@' . self::SIGNUP_TOKEN, HttpMethod::gets(), 'signup_step2_get', [NotLoginMiddleware::class, SignupStep2FilterMiddleware::class]) |
102 | ->addAction('signup/:token@' . self::SIGNUP_TOKEN, HttpMethod::Post, 'signup_step2_post', [NotLoginMiddleware::class, SignupStep2FilterMiddleware::class, CsrfMiddleware::class]) |
103 | ->addAction('user', HttpMethod::gets(), 'user', [UserAccountFilterMiddleware::class]) |
104 | ->addAction('user/edit', HttpMethod::gets(), 'user_edit_get', [UserAccountFilterMiddleware::class]) |
105 | ->addAction('user/edit', HttpMethod::Post, 'user_edit_post', [UserAccountFilterMiddleware::class, CsrfMiddleware::class]) |
106 | ->addAction('user/api', HttpMethod::gets(), 'user_api_get', [UserAccountFilterMiddleware::class]) |
107 | ->addAction('user/api', HttpMethod::Post, 'user_api_post', [UserAccountFilterMiddleware::class]) |
108 | ->addAction('user/password', HttpMethod::gets(), 'user_password_get', [UserAccountFilterMiddleware::class]) |
109 | ->addAction('user/password', HttpMethod::Post, 'user_password_post', [UserAccountFilterMiddleware::class, CsrfMiddleware::class]) |
110 | ->addAction('user/email', HttpMethod::gets(), 'user_email_get', [UserAccountFilterMiddleware::class]) |
111 | ->addAction('user/email', HttpMethod::Post, 'user_email_post', [UserAccountFilterMiddleware::class, CsrfMiddleware::class]) |
112 | ->addAction('user/plugin', HttpMethod::gets(), 'user_plugin_register_get', [UserAccountFilterMiddleware::class]) |
113 | ->addAction('user/plugin', HttpMethod::Post, 'user_plugin_register_post', [UserAccountFilterMiddleware::class, CsrfMiddleware::class]) |
114 | ->addAction('user/plugin/:plugin_id@' . self::PLUGIN_ID, HttpMethod::gets(), 'user_plugin_update_get', [UserAccountFilterMiddleware::class, UserPluginEditFilterMiddleware::class]) |
115 | ->addAction('user/plugin/:plugin_id@' . self::PLUGIN_ID, HttpMethod::Post, 'user_plugin_update_post', [UserAccountFilterMiddleware::class, UserPluginEditFilterMiddleware::class, CsrfMiddleware::class]) |
116 | ->addAction('user/audit-logs', HttpMethod::Get, 'user_audit_logs_top', [UserAccountFilterMiddleware::class]) |
117 | ->addAction('user/audit-logs/page/:page_number@\d++', HttpMethod::Get, 'user_audit_logs_page', [UserAccountFilterMiddleware::class]) |
118 | ->addAction('user/audit-logs/download', HttpMethod::Get, 'user_audit_logs_download', [UserAccountFilterMiddleware::class]) |
119 | /* AUTO-FORMAT */, |
120 | (new Route('password', PasswordController::class, [NotLoginMiddleware::class])) |
121 | ->addAction('reminder', HttpMethod::gets(), 'reminder_get') |
122 | ->addAction('reminder', HttpMethod::Post, 'reminder_post', [CsrfMiddleware::class]) |
123 | ->addAction('reminding/:token@' . self::PASSWORD_REMINDER_TOKEN, HttpMethod::Get, 'reminding') |
124 | ->addAction('reset/:token@' . self::PASSWORD_REMINDER_TOKEN, HttpMethod::Get, 'reset_get') |
125 | ->addAction('reset/:token@' . self::PASSWORD_REMINDER_TOKEN, HttpMethod::Post, 'reset_post', [CsrfMiddleware::class]) |
126 | /* AUTO-FORMAT */, |
127 | (new Route('plugin', PluginController::class)) |
128 | ->addAction(':plugin_id@' . self::PLUGIN_ID, HttpMethod::gets(), 'detail', [PluginIdMiddleware::class]) |
129 | /* AUTO-FORMAT */, |
130 | (new Route('management', ManagementController::class, [AdministratorAccountFilterMiddleware::class])) |
131 | ->addAction('setup', HttpMethod::Get, 'setup_get', [Route::CLEAR_MIDDLEWARE, SetupAccountFilterMiddleware::class]) |
132 | ->addAction('setup', HttpMethod::Post, 'setup_post', [Route::CLEAR_MIDDLEWARE, SetupAccountFilterMiddleware::class]) |
133 | ->addAction('environment', HttpMethod::Get, 'environment') |
134 | ->addAction('configuration', HttpMethod::Get, 'configuration') |
135 | ->addAction('configuration/edit', HttpMethod::Get, 'configuration_edit_get') |
136 | ->addAction('configuration/edit', HttpMethod::Post, 'configuration_edit_post', [CsrfMiddleware::class]) |
137 | ->addAction('backup', HttpMethod::Post, 'backup', [CsrfMiddleware::class]) |
138 | ->addAction('delete-old-data', HttpMethod::Post, 'delete_old_data', [CsrfMiddleware::class]) |
139 | ->addAction('database-maintenance', HttpMethod::Get, 'database_maintenance_get') |
140 | ->addAction('database-maintenance', HttpMethod::Post, 'database_maintenance_post', [CsrfMiddleware::class]) |
141 | ->addAction('database-download', HttpMethod::Get, 'database_download_get') |
142 | ->addAction('mail-send', HttpMethod::Get, 'mail_send_get') |
143 | ->addAction('mail-send', HttpMethod::Post, 'mail_send_post') |
144 | ->addAction('php-evaluate', HttpMethod::Get, 'php_evaluate_get') |
145 | ->addAction('php-evaluate', HttpMethod::Post, 'php_evaluate_post', [CsrfMiddleware::class]) |
146 | ->addAction('default-plugin', HttpMethod::Get, 'default_plugin_get') |
147 | ->addAction('default-plugin', HttpMethod::Post, 'default_plugin_post', [CsrfMiddleware::class]) |
148 | ->addAction('delete-old-data', HttpMethod::Post, 'delete_old_data', [CsrfMiddleware::class]) |
149 | ->addAction('cache-rebuild', HttpMethod::Post, 'cache_rebuild', [CsrfMiddleware::class]) |
150 | ->addAction('vacuum-access-log', HttpMethod::Post, 'vacuum_access_log', [CsrfMiddleware::class]) |
151 | ->addAction('clear-deploy-progress', HttpMethod::Post, 'clear_deploy_progress', [CsrfMiddleware::class]) |
152 | ->addAction('plugin-category', HttpMethod::Get, 'plugin_category_get') |
153 | ->addAction('feedback', HttpMethod::Get, 'feedback_list_top') |
154 | ->addAction('feedback/page/:page_number@\d++', HttpMethod::Get, 'feedback_list_page') |
155 | ->addAction('feedback/:sequence@\d++', HttpMethod::Get, 'feedback_detail_get') |
156 | ->addAction('feedback/:sequence@\d++', HttpMethod::Post, 'feedback_detail_post', [CsrfMiddleware::class]) |
157 | ->addAction('crash-report', HttpMethod::Get, 'crash_report_list_top') |
158 | ->addAction('crash-report/page/:page_number@\d++', HttpMethod::Get, 'crash_report_list_page') |
159 | ->addAction('crash-report/:sequence@\d++', HttpMethod::Get, 'crash_report_detail_get') |
160 | ->addAction('crash-report/:sequence@\d++', HttpMethod::Post, 'crash_report_detail_post', [CsrfMiddleware::class]) |
161 | ->addAction('version', HttpMethod::Get, 'version_get') |
162 | ->addAction('version', HttpMethod::Post, 'version_post', [CsrfMiddleware::class]) |
163 | ->addAction('log', HttpMethod::Get, 'log_list') |
164 | ->addAction('log/:log_name@\w+\.log', HttpMethod::Get, 'log_detail_get') |
165 | ->addAction('log/:log_name@\w+\.log', HttpMethod::Post, 'log_detail_post', [CsrfMiddleware::class]) |
166 | ->addAction('markdown', HttpMethod::Get, 'markdown') |
167 | /* AUTO-FORMAT */, |
168 | (new Route('management/control', ManagementControlController::class, [AdministratorAccountFilterMiddleware::class])) |
169 | ->addAction('user', HttpMethod::Get, 'user_list_get') |
170 | ->addAction('backup', HttpMethod::Get, 'backup_list_get') |
171 | ->addAction('backup/:file_name@\w+\.zip', HttpMethod::Get, 'backup_detail_get') |
172 | /* AUTO-FORMAT */, |
173 | (new Route('tool', ToolController::class)) |
174 | ->addAction('base64', HttpMethod::Get, 'base64_get') |
175 | ->addAction('base64', HttpMethod::Post, 'base64_post') |
176 | ->addAction('json', HttpMethod::Get, 'json_get') |
177 | ->addAction('json', HttpMethod::Post, 'json_post') |
178 | /* AUTO-FORMAT */, |
179 | (new Route('ajax', AjaxController::class, [UserAccountFilterMiddleware::class])) |
180 | ->addAction('markdown', HttpMethod::Post, 'markdown') |
181 | ->addAction('plugin-category', HttpMethod::Post, 'plugin_category_post', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
182 | ->addAction('plugin-category/:plugin_category_id@.+', HttpMethod::Patch, 'plugin_category_patch', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
183 | ->addAction('plugin-category/:plugin_category_id@.+', HttpMethod::Delete, 'plugin_category_delete', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
184 | ->addAction('log/:log_name@\w+\.log', HttpMethod::Delete, 'log_delete', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
185 | ->addAction('feedback/:sequence@\d++', HttpMethod::Delete, 'feedback_delete', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
186 | ->addAction('crash-report/:sequence@\d++', HttpMethod::Delete, 'crash_report_delete', [CsrfMiddleware::class, AdministratorAccountFilterMiddleware::class]) |
187 | /* AUTO-FORMAT */, |
188 | (new Route('api/development', DevelopmentApiController::class, [DevelopmentMiddleware::class])) |
189 | ->addAction('initialize', HttpMethod::Post, 'initialize') |
190 | ->addAction('administrator', HttpMethod::Post, 'administrator') |
191 | /* AUTO-FORMAT */, |
192 | (new Route('api/plugin', PluginApiController::class, [ApiCorsMiddleware::class])) |
193 | ->addAction('exists', HttpMethod::Post, 'exists') |
194 | ->addAction('generate-plugin-id', HttpMethod::gets(), 'generate_plugin_id') |
195 | ->addAction('information', HttpMethod::Post, 'information') |
196 | /* AUTO-FORMAT */, |
197 | (new Route('api/application', ApplicationApiController::class, [ApiCorsMiddleware::class])) |
198 | ->addAction('feedback', HttpMethod::Post, 'feedback') |
199 | ->addAction('crash-report', HttpMethod::Post, 'crash_report') |
200 | ->addAction('version/update', HttpMethod::Get, 'version_update') |
201 | /* AUTO-FORMAT */, |
202 | (new Route('api/account', AccountApiController::class, [ApiCorsMiddleware::class, ApiUserAccountFilterMiddleware::class, ApiAdministratorAccountFilterMiddleware::class])) |
203 | /* AUTO-FORMAT */, |
204 | (new Route('api/administrator', AdministratorApiController::class, [ApiCorsMiddleware::class, ApiAdministratorAccountFilterMiddleware::class])) |
205 | ->addAction('backup', HttpMethod::Post, 'backup') |
206 | ->addAction('delete-old-data', HttpMethod::Post, 'delete_old_data') |
207 | ->addAction('cache-rebuild', HttpMethod::Post, 'cache_rebuild') |
208 | ->addAction('vacuum-access-log', HttpMethod::Post, 'vacuum_access_log') |
209 | ->addAction('deploy/:mode@.+', HttpMethod::Post, 'deploy') |
210 | ->addAction('pe/version', HttpMethod::Post, 'pe_version') |
211 | /* AUTO-FORMAT */, |
212 | ] |
213 | ); |
214 | } |
215 | } |