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 Infrastructure\Administration\Company\Controller; |
15
|
|
|
|
16
|
|
|
use Domain\Administration\Company\Command\EditCompany; |
17
|
|
|
use Domain\Common\Model\ContactUuid; |
18
|
|
|
use Domain\Common\Model\VO\EmailField; |
19
|
|
|
use Domain\Common\Model\VO\NameField; |
20
|
|
|
use Domain\Common\Model\VO\PhoneField; |
21
|
|
|
use Infrastructure\Administration\Company\Form\CompanyType; |
22
|
|
|
use Infrastructure\Common\MessengerCommandBus; |
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
24
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
25
|
|
|
use Symfony\Component\HttpFoundation\Request; |
26
|
|
|
use Symfony\Component\HttpFoundation\Response; |
27
|
|
|
|
28
|
|
|
class PutCompanyController extends AbstractController |
29
|
|
|
{ |
30
|
|
|
private MessengerCommandBus $commandBus; |
31
|
|
|
|
32
|
|
|
public function __construct(MessengerCommandBus $commandBus) |
33
|
|
|
{ |
34
|
|
|
$this->commandBus = $commandBus; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function __invoke(Request $request, string $uuid): Response |
38
|
|
|
{ |
39
|
|
|
$company = $request->request->get('company'); |
40
|
|
|
|
41
|
|
|
try { |
42
|
|
|
$command = new EditCompany( |
43
|
|
|
ContactUuid::fromString($uuid), |
44
|
|
|
NameField::fromString($company['name']), |
45
|
|
|
$company['address'], |
46
|
|
|
$company['zipCode'], |
47
|
|
|
$company['town'], |
48
|
|
|
$company['country'], |
49
|
|
|
PhoneField::fromString($company['phone']), |
50
|
|
|
PhoneField::fromString($company['facsimile']), |
51
|
|
|
EmailField::fromString($company['email']), |
52
|
|
|
$company['contact'], |
53
|
|
|
PhoneField::fromString($company['cellphone']) |
54
|
|
|
); |
55
|
|
|
$this->commandBus->dispatch($command); |
56
|
|
|
} catch (\DomainException $exception) { |
57
|
|
|
$form = $this->createForm(CompanyType::class, $company, [ |
58
|
|
|
'action' => $this->generateUrl('admin_company_edit'), |
59
|
|
|
]); |
60
|
|
|
$this->addFlash('error', $exception->getMessage()); |
61
|
|
|
|
62
|
|
|
return $this->render('Administration/Company/edit.html.twig', [ |
63
|
|
|
'form' => $form->createView(), |
64
|
|
|
'errors' => $exception, |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->addFlash('success', 'Company updated started!'); |
69
|
|
|
|
70
|
|
|
return new RedirectResponse($this->generateUrl('admin_company_index')); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|