Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PluginIdMiddleware | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
42 | |||
handleAfter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Middleware; |
6 | |
7 | use PeServer\App\Models\AppDatabase; |
8 | use PeServer\App\Models\AppDatabaseCache; |
9 | use PeServer\App\Models\Dao\Entities\PluginsEntityDao; |
10 | use PeServer\App\Models\SessionKey; |
11 | use PeServer\Core\Http\HttpRequest; |
12 | use PeServer\Core\Http\HttpRequestExists; |
13 | use PeServer\Core\Http\HttpResponse; |
14 | use PeServer\Core\Http\HttpStatus; |
15 | use PeServer\Core\Mvc\Middleware\IMiddleware; |
16 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
17 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
18 | use PeServer\Core\Uuid; |
19 | |
20 | final class PluginIdMiddleware implements IMiddleware |
21 | { |
22 | public function __construct( |
23 | private AppDatabaseCache $dbCache |
24 | ) { |
25 | } |
26 | |
27 | |
28 | //[IMiddleware] |
29 | |
30 | final public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
31 | { |
32 | $pluginIdState = $argument->request->exists('plugin_id'); |
33 | if ($pluginIdState->exists && $pluginIdState->kind === HttpRequestExists::KIND_URL) { |
34 | $pluginId = $argument->request->getValue($pluginIdState->name); |
35 | // ここにきてるってことはユーザーフィルタを通過しているのでセッションを見る必要はないけど一応ね |
36 | if (Uuid::isGuid($pluginId)) { |
37 | $pluginId = Uuid::adjustGuid($pluginId); |
38 | |
39 | $plugins = $this->dbCache->readPluginInformation(); |
40 | foreach ($plugins->items as $plugin) { |
41 | if (Uuid::isEqualGuid($plugin->pluginId, $pluginId)) { |
42 | return MiddlewareResult::none(); |
43 | } |
44 | } |
45 | } |
46 | } |
47 | |
48 | return MiddlewareResult::error(HttpStatus::NotFound); |
49 | } |
50 | |
51 | public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
52 | { |
53 | return MiddlewareResult::none(); |
54 | } |
55 | } |