Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginApiInformationLogic
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 executeImpl
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Api\PluginApi;
6
7use PeServer\App\Models\AppDatabaseCache;
8use PeServer\Core\Mvc\LogicCallMode;
9use PeServer\Core\Mvc\LogicParameter;
10use PeServer\App\Models\Domain\Api\ApiLogicBase;
11use PeServer\App\Models\ResponseJson;
12use PeServer\Core\Collection\Arr;
13use PeServer\Core\Uuid;
14
15class PluginApiInformationLogic extends ApiLogicBase
16{
17    public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache)
18    {
19        parent::__construct($parameter);
20    }
21
22    #region ApiLogicBase
23
24    protected function validateImpl(LogicCallMode $callMode): void
25    {
26        //NOP
27    }
28
29    protected function executeImpl(LogicCallMode $callMode): void
30    {
31        $json = $this->getRequestJson();
32        /** @var string[] */
33        $pluginIds = $json['plugin_ids'];
34
35        $plugins = $this->dbCache->readPluginInformation();
36        /** @var array<string,array<mixed>> */
37        $items = [];
38        foreach ($pluginIds as $pluginId) {
39            foreach ($plugins->items as $plugin) {
40                if (Uuid::isEqualGuid($plugin->pluginId, $pluginId)) {
41                    $items[$plugin->pluginId] = [
42                        'user_id' => $plugin->userId,
43                        'plugin_name' => $plugin->pluginName,
44                        'display_name' => $plugin->displayName,
45                        'state' => $plugin->state,
46                        'description' => $plugin->description,
47                        'check_url' => $plugin->urls['check'],
48                        'project_url' => $plugin->urls['project'],
49                    ];
50                    break;
51                }
52            }
53        }
54
55
56        $this->setResponseJson(ResponseJson::success([
57            'plugins' => $items,
58        ]));
59    }
60
61    #endregion
62}