|
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\Handler; |
|
15
|
|
|
|
|
16
|
|
|
use Company\Application\Command\CreateCompany as CreateCompanyCommand; |
|
17
|
|
|
use Company\Application\Factory\CreateCompany as CreateCompanyFactory; |
|
18
|
|
|
use Company\Domain\Exception\CompanyAlreadyExistException; |
|
19
|
|
|
use Company\Infrastructure\Storage\ReadCompany; |
|
20
|
|
|
use Company\Infrastructure\Storage\SaveCompany; |
|
21
|
|
|
use Core\Domain\Protocol\Common\Command\CommandHandlerInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class CreateCompany implements CommandHandlerInterface |
|
24
|
|
|
{ |
|
25
|
|
|
private ReadCompany $readCompany; |
|
26
|
|
|
private SaveCompany $saveCompany; |
|
27
|
|
|
private CreateCompanyFactory $createCompany; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct( |
|
30
|
|
|
ReadCompany $readCompany, |
|
31
|
|
|
SaveCompany $saveCompany, |
|
32
|
|
|
CreateCompanyFactory $createCompany |
|
33
|
|
|
) { |
|
34
|
|
|
$this->readCompany = $readCompany; |
|
35
|
|
|
$this->saveCompany = $saveCompany; |
|
36
|
|
|
$this->createCompany = $createCompany; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function __invoke(CreateCompanyCommand $command): void |
|
40
|
|
|
{ |
|
41
|
|
|
if ($this->readCompany->companyExist()) { |
|
42
|
|
|
throw new CompanyAlreadyExistException(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$company = $this->createCompany->createCompany($command); |
|
46
|
|
|
|
|
47
|
|
|
$this->saveCompany->save($company); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|