1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
7
|
|
|
* |
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Company\Infrastructure\Storage\Settings; |
15
|
|
|
|
16
|
|
|
use Company\Domain\Exception\SettingsNotFoundException; |
17
|
|
|
use Company\Domain\Model\Settings; |
18
|
|
|
use Company\Domain\Model\VO\Currency; |
19
|
|
|
use Company\Domain\Model\VO\Locale; |
20
|
|
|
use Company\Domain\Storage\Settings\ReadSettings as ReadSettingsDomain; |
21
|
|
|
use Company\Domain\Storage\Settings\SettingsEntity; |
22
|
|
|
use Company\Infrastructure\Doctrine\Repository\SettingsRepository; |
23
|
|
|
use Core\Domain\Common\Model\VO\ResourceUuidInterface; |
24
|
|
|
|
25
|
|
|
class ReadSettings implements ReadSettingsDomain |
26
|
|
|
{ |
27
|
|
|
private SettingsRepository $settingsRepository; |
28
|
|
|
|
29
|
|
|
public function __construct(SettingsRepository $settingsRepository) |
30
|
|
|
{ |
31
|
|
|
$this->settingsRepository = $settingsRepository; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function findAll(): array |
35
|
|
|
{ |
36
|
|
|
return $this->settingsRepository->findAll(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function findOneByUuid(ResourceUuidInterface $uuid): Settings |
40
|
|
|
{ |
41
|
|
|
/** @var SettingsEntity $settingsEntity */ |
42
|
|
|
$settingsEntity = $this->settingsRepository->findOneByUuid($uuid); |
43
|
|
|
|
44
|
|
|
return $this->trasformToModel($settingsEntity); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function findByLocale(Locale $locale): Settings |
48
|
|
|
{ |
49
|
|
|
$settingsEntity = $this->settingsRepository->findByLocale($locale); |
50
|
|
|
|
51
|
|
|
return $this->trasformToModel($settingsEntity); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function save(SettingsEntity $settings): void |
55
|
|
|
{ |
56
|
|
|
$this->settingsRepository->save($settings); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function remove(SettingsEntity $settings): void |
60
|
|
|
{ |
61
|
|
|
$this->settingsRepository->remove($settings); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function findByCurrency(Currency $currency): Settings |
65
|
|
|
{ |
66
|
|
|
$settingsEntity = $this->settingsRepository->findByCurrency($currency); |
67
|
|
|
|
68
|
|
|
return $this->trasformToModel($settingsEntity); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function settingsExists(): bool |
72
|
|
|
{ |
73
|
|
|
return $this->settingsRepository->settingsExists(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function findDefaultSettings(): Settings |
77
|
|
|
{ |
78
|
|
|
$settingsEntity = $this->settingsRepository->findOne(); |
79
|
|
|
|
80
|
|
|
return $this->trasformToModel($settingsEntity); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function trasformToModel(?SettingsEntity $settingsEntity): Settings |
84
|
|
|
{ |
85
|
|
|
if (!$settingsEntity instanceof SettingsEntity) { |
86
|
|
|
throw new SettingsNotFoundException(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $settingsEntity->toModel(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|