Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginApiGeneratePluginIdLogic
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
20
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 / 14
0.00% covered (danger)
0.00%
0 / 1
6
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\Collection\Collections;
14use PeServer\Core\Uuid;
15
16class PluginApiGeneratePluginIdLogic extends ApiLogicBase
17{
18    public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache)
19    {
20        parent::__construct($parameter);
21    }
22
23    #region ApiLogicBase
24
25    protected function validateImpl(LogicCallMode $callMode): void
26    {
27        //NOP
28    }
29
30    protected function executeImpl(LogicCallMode $callMode): void
31    {
32        $plugins = $this->dbCache->readPluginInformation();
33        $pluginCollection = Collections::from($plugins->items);
34
35        $pluginId = Uuid::generateGuid();
36
37        $existsPluginId = true;
38        do {
39            $existsPluginId = $pluginCollection->any(function ($i) use ($pluginId) {
40                return Uuid::isEqualGuid($i->pluginId, $pluginId);
41            });
42
43            if ($existsPluginId) {
44                $this->logger->info('重複プラグインID -> {0}', $pluginId);
45                $pluginId = Uuid::generateGuid();
46            }
47        } while ($existsPluginId);
48
49        $this->setResponseJson(ResponseJson::success([
50            'plugin_id' => $pluginId,
51        ]));
52    }
53
54    #endregion
55}