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\Application\Settings\Handler; |
15
|
|
|
|
16
|
|
|
use Company\Application\Settings\DTO\OutputSettings; |
17
|
|
|
use Company\Application\Settings\Factory\CreateOutputSettings; |
18
|
|
|
use Company\Application\Settings\Query\GetSettings; |
19
|
|
|
use Company\Domain\Model\VO\Currency; |
20
|
|
|
use Company\Domain\Model\VO\Locale; |
21
|
|
|
use Company\Domain\Storage\Settings\ReadSettings; |
22
|
|
|
use Core\Domain\Common\Query\QueryHandlerInterface; |
23
|
|
|
|
24
|
|
|
class GetSettingsHandler implements QueryHandlerInterface |
25
|
|
|
{ |
26
|
|
|
private ReadSettings $readSettings; |
27
|
|
|
private CreateOutputSettings $createOutputSettings; |
28
|
|
|
|
29
|
|
|
public function __construct(ReadSettings $readSettings, CreateOutputSettings $createOutputSettings) |
30
|
|
|
{ |
31
|
|
|
$this->readSettings = $readSettings; |
32
|
|
|
$this->createOutputSettings = $createOutputSettings; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function __invoke(GetSettings $query): ?OutputSettings |
36
|
|
|
{ |
37
|
|
|
if (null === $query->currency() && null === $query->locale()) { |
38
|
|
|
$settingsModel = $this->readSettings->findDefaultSettings(); |
39
|
|
|
|
40
|
|
|
return $this->createOutputSettings->create($settingsModel); |
41
|
|
|
} |
42
|
|
|
if (null !== $query->locale()) { |
43
|
|
|
$settingsModel = $this->readSettings->findByLocale(Locale::fromString($query->locale())); |
44
|
|
|
|
45
|
|
|
return $this->createOutputSettings->create($settingsModel); |
46
|
|
|
} |
47
|
|
|
if (null !== $query->currency()) { |
48
|
|
|
$settingsModel = $this->readSettings->findByCurrency(Currency::fromString($query->currency())); |
49
|
|
|
|
50
|
|
|
return $this->createOutputSettings->create($settingsModel); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return null; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|