|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Component\Spacecraft\System\Control; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Component\Spacecraft\System\Exception\AlreadyOffException; |
|
6
|
|
|
use Stu\Component\Spacecraft\System\Exception\DeactivationConditionsNotMetException; |
|
7
|
|
|
use Stu\Component\Spacecraft\System\Exception\SystemNotDeactivatableException; |
|
8
|
|
|
use Stu\Component\Spacecraft\System\Exception\SystemNotFoundException; |
|
9
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
|
10
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
|
11
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
12
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
13
|
|
|
use Stu\Orm\Repository\SpacecraftRepositoryInterface; |
|
14
|
|
|
|
|
15
|
|
|
class SystemDeactivation |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function __construct( |
|
18
|
|
|
private readonly SpacecraftSystemManagerInterface $spacecraftSystemManager, |
|
19
|
|
|
private readonly SpacecraftRepositoryInterface $spacecraftRepository |
|
20
|
1 |
|
) {} |
|
21
|
|
|
|
|
22
|
|
|
public function deactivateIntern( |
|
23
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
24
|
|
|
spacecraftSystemTypeEnum $type, |
|
25
|
|
|
InformationInterface $informations |
|
26
|
|
|
): bool { |
|
27
|
|
|
$systemName = $type->getDescription(); |
|
28
|
|
|
$ship = $wrapper->get(); |
|
29
|
|
|
|
|
30
|
|
|
try { |
|
31
|
|
|
$this->spacecraftSystemManager->deactivate($wrapper, $type); |
|
32
|
|
|
$this->spacecraftRepository->save($ship); |
|
33
|
|
|
$informations->addInformationf(_('%s: System %s deaktiviert'), $ship->getName(), $systemName); |
|
34
|
|
|
return true; |
|
35
|
|
|
} catch (AlreadyOffException) { |
|
36
|
|
|
$informations->addInformationf(_('%s: System %s ist bereits deaktiviert'), $ship->getName(), $systemName); |
|
37
|
|
|
} catch (SystemNotDeactivatableException) { |
|
38
|
|
|
$informations->addInformationf(_('%s: [b][color=#ff2626]System %s besitzt keinen Deaktivierungsmodus[/color][/b]'), $ship->getName(), $systemName); |
|
39
|
|
|
} catch (DeactivationConditionsNotMetException $e) { |
|
40
|
|
|
$informations->addInformationf(_('%s: [b][color=#ff2626]System %s konnte nicht deaktiviert werden, weil %s[/color][/b]'), $ship->getName(), $systemName, $e->getMessage()); |
|
41
|
|
|
} catch (SystemNotFoundException) { |
|
42
|
|
|
$informations->addInformationf(_('%s: System %s nicht vorhanden'), $ship->getName(), $systemName); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|