1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace FlightLog\Http\Web\Controller; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use FlightLog\Application\Damage\Command\CreateDamageCommand; |
8
|
|
|
use FlightLog\Application\Damage\Command\CreateDamageCommandHandler; |
9
|
|
|
use FlightLog\Application\Pilot\Command\CreateUpdatePilotInformationCommand; |
10
|
|
|
use FlightLog\Application\Pilot\Command\CreateUpdatePilotInformationCommandHandler; |
11
|
|
|
use FlightLog\Domain\Pilot\ValueObject\PilotId; |
12
|
|
|
use FlightLog\Http\Web\Form\DamageCreationForm; |
13
|
|
|
use FlightLog\Http\Web\Form\PilotForm; |
14
|
|
|
use FlightLog\Infrastructure\Pilot\Repository\PilotRepository; |
15
|
|
|
|
16
|
|
|
final class PilotEditController extends WebController |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function index(){ |
20
|
|
|
$id = $this->request->getParam('id'); |
21
|
|
|
|
22
|
|
|
if($id === null){ |
23
|
|
|
$this->renderHtml('<p>Paramètre ID non fournis.</p>'); |
24
|
|
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$command = new CreateUpdatePilotInformationCommand($id); |
28
|
|
|
|
29
|
|
|
if($this->getPilotRepository()->exist(PilotId::create($id))){ |
30
|
|
|
$command->fromPilot($this->getPilotRepository()->getById(PilotId::create($id))); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$form = new PilotForm('pilot', $this->db); |
34
|
|
|
$form->bind($command); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$user = new \User($this->db); |
37
|
|
|
$user->fetch($id); |
38
|
|
|
|
39
|
|
View Code Duplication |
if($this->request->isPost()){ |
|
|
|
|
40
|
|
|
$form->setData($this->request->getPostParameters()); |
41
|
|
|
|
42
|
|
|
if(!$form->validate()){ |
43
|
|
|
return $this->render('pilot/edit.phtml', [ |
44
|
|
|
'form' => $form, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
try{ |
49
|
|
|
$this->handle($form->getObject()); |
|
|
|
|
50
|
|
|
}catch(\Exception $e){ |
51
|
|
|
print $e->getMessage(); |
52
|
|
|
dol_syslog($e->getMessage(), LOG_ERR); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
return $this->redirect($_SERVER["PHP_SELF"].'?id='.$id.'&r=edit_pilot'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->render('pilot/edit.phtml', [ |
60
|
|
|
'pilotForm' => $form, |
61
|
|
|
'pilot' => $user, |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param CreateUpdatePilotInformationCommand $command |
67
|
|
|
* |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
private function handle(CreateUpdatePilotInformationCommand $command) |
71
|
|
|
{ |
72
|
|
|
$this->getHandler()->__invoke($command); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return CreateUpdatePilotInformationCommandHandler() |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
private function getHandler(){ |
79
|
|
|
return new CreateUpdatePilotInformationCommandHandler($this->getPilotRepository()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function getPilotRepository() |
83
|
|
|
{ |
84
|
|
|
return new PilotRepository($this->db); |
85
|
|
|
} |
86
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: