1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Spacecraft\Lib\Auxiliary; |
4
|
|
|
|
5
|
|
|
use Stu\Component\Spacecraft\System\Control\ActivatorDeactivatorHelperInterface; |
6
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
7
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeInterface; |
8
|
|
|
use Stu\Lib\Information\InformationWrapper; |
9
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
10
|
|
|
use Stu\Orm\Entity\SpacecraftSystem; |
11
|
|
|
use Stu\Orm\Repository\SpacecraftRepositoryInterface; |
12
|
|
|
|
13
|
|
|
class SpacecraftStartup implements SpacecraftStartupInterface |
14
|
|
|
{ |
15
|
3 |
|
public function __construct( |
16
|
|
|
private readonly SpacecraftRepositoryInterface $spacecraftRepository, |
17
|
|
|
private readonly SpacecraftSystemManagerInterface $spacecraftSystemManager, |
18
|
|
|
private readonly ActivatorDeactivatorHelperInterface $helper |
19
|
3 |
|
) {} |
20
|
|
|
|
21
|
2 |
|
public function startup(SpacecraftWrapperInterface $wrapper, array $additionalSystemTypes = []): void |
22
|
|
|
{ |
23
|
2 |
|
$isSaveNeeded = false; |
24
|
|
|
|
25
|
2 |
|
$wrapper |
26
|
2 |
|
->get() |
27
|
2 |
|
->getSystems() |
28
|
2 |
|
->filter(fn(SpacecraftSystem $system): bool => !$system->getMode()->isActivated() && $system->isHealthy()) |
29
|
2 |
|
->map(fn(SpacecraftSystem $system): SpacecraftSystemTypeInterface => $this->spacecraftSystemManager->lookupSystem($system->getSystemType())) |
30
|
2 |
|
->filter(fn(SpacecraftSystemTypeInterface $systemType): bool => $systemType->getDefaultMode()->isActivated() |
31
|
2 |
|
|| in_array($systemType->getSystemType(), $additionalSystemTypes)) |
32
|
2 |
|
->forAll(function (int $key, SpacecraftSystemTypeInterface $systemType) use ($wrapper, &$isSaveNeeded): bool { |
33
|
2 |
|
$isSaveNeeded = $this->helper->activate($wrapper, $systemType->getSystemType(), new InformationWrapper()) || $isSaveNeeded; |
34
|
2 |
|
return true; |
35
|
2 |
|
}); |
36
|
|
|
|
37
|
2 |
|
if ($isSaveNeeded) { |
38
|
1 |
|
$this->spacecraftRepository->save($wrapper->get()); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|