Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
PluginApiExistsLogic | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateImpl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
executeImpl | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Api\PluginApi; |
6 | |
7 | use PeServer\App\Models\AppDatabaseCache; |
8 | use PeServer\App\Models\Domain\Api\ApiLogicBase; |
9 | use PeServer\App\Models\ResponseJson; |
10 | use PeServer\Core\Collection\Arr; |
11 | use PeServer\Core\Collection\Collections; |
12 | use PeServer\Core\Text; |
13 | use PeServer\Core\Mvc\LogicCallMode; |
14 | use PeServer\Core\Mvc\LogicParameter; |
15 | use PeServer\Core\Uuid; |
16 | |
17 | class PluginApiExistsLogic extends ApiLogicBase |
18 | { |
19 | public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache) |
20 | { |
21 | parent::__construct($parameter); |
22 | } |
23 | |
24 | #region ApiLogicBase |
25 | |
26 | protected function validateImpl(LogicCallMode $callMode): void |
27 | { |
28 | //NOP |
29 | } |
30 | |
31 | protected function executeImpl(LogicCallMode $callMode): void |
32 | { |
33 | $json = $this->getRequestJson(); |
34 | $pluginId = $json['plugin_id'] ?? Text::EMPTY; |
35 | $pluginName = $json['plugin_name'] ?? Text::EMPTY; |
36 | |
37 | $plugins = $this->dbCache->readPluginInformation(); |
38 | $pluginCollection = Collections::from($plugins->items); |
39 | $existsPluginId = $pluginCollection->any(function ($i) use ($pluginId) { |
40 | return Uuid::isEqualGuid($i->pluginId, $pluginId); |
41 | }); |
42 | $existsPluginName = $pluginCollection->any(function ($i) use ($pluginName) { |
43 | return $i->pluginName === $pluginName; |
44 | }); |
45 | |
46 | $this->setResponseJson(ResponseJson::success([ |
47 | 'plugin_id' => $existsPluginId, |
48 | 'plugin_name' => $existsPluginName, |
49 | ])); |
50 | } |
51 | |
52 | #endregion |
53 | } |