conferencetools /
checkin-module
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ConferenceTools\Checkin\Domain\CommandHandler; |
||
| 4 | |||
| 5 | use Carnage\Cqrs\Aggregate\Identity\GeneratorInterface; |
||
| 6 | use Carnage\Cqrs\MessageHandler\AbstractMethodNameMessageHandler; |
||
| 7 | use Carnage\Cqrs\Persistence\Repository\RepositoryInterface; |
||
| 8 | use ConferenceTools\Checkin\Domain\Command\Delegate\CheckInDelegate; |
||
| 9 | use ConferenceTools\Checkin\Domain\Command\Delegate\RegisterDelegate; |
||
| 10 | use ConferenceTools\Checkin\Domain\Command\Delegate\UpdateDelegateInformation; |
||
| 11 | use ConferenceTools\Checkin\Domain\Model\Delegate\Delegate as DelegateModel; |
||
| 12 | |||
| 13 | class Delegate extends AbstractMethodNameMessageHandler |
||
| 14 | { |
||
| 15 | private $idGenerator; |
||
| 16 | |||
| 17 | private $repository; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Delegate constructor. |
||
| 21 | * @param $idGenerator |
||
| 22 | * @param $repository |
||
| 23 | */ |
||
| 24 | 4 | public function __construct(RepositoryInterface $repository, GeneratorInterface $idGenerator) |
|
| 25 | { |
||
| 26 | 4 | $this->idGenerator = $idGenerator; |
|
| 27 | 4 | $this->repository = $repository; |
|
| 28 | 4 | } |
|
| 29 | |||
| 30 | 1 | protected function handleRegisterDelegate(RegisterDelegate $command): void |
|
| 31 | { |
||
| 32 | 1 | $delegate = DelegateModel::register( |
|
| 33 | 1 | $this->idGenerator->generateIdentity(), |
|
| 34 | 1 | $command->getDelegateInfo(), |
|
| 35 | 1 | $command->getTicket(), |
|
| 36 | 1 | $command->getPurchaserEmail() |
|
| 37 | ); |
||
| 38 | |||
| 39 | 1 | $this->repository->save($delegate); |
|
| 40 | 1 | } |
|
| 41 | |||
| 42 | 1 | protected function handleUpdateDelegateInformation(UpdateDelegateInformation $command): void |
|
| 43 | { |
||
| 44 | 1 | $delegate = $this->loadDelegate($command->getDelegateId()); |
|
| 45 | 1 | $delegate->updateDelegateInformation($command->getDelegateInfo()); |
|
| 46 | 1 | $this->repository->save($delegate); |
|
| 47 | 1 | } |
|
| 48 | |||
| 49 | 2 | protected function handleCheckInDelegate(CheckInDelegate $command): void |
|
| 50 | { |
||
| 51 | 2 | $delegate = $this->loadDelegate($command->getId()); |
|
| 52 | 2 | $delegate->checkIn(); |
|
| 53 | 1 | $this->repository->save($delegate); |
|
| 54 | 1 | } |
|
| 55 | |||
| 56 | 3 | private function loadDelegate(string $delegateId): DelegateModel |
|
| 57 | { |
||
| 58 | 3 | return $this->repository->load($delegateId); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 59 | } |
||
| 60 | } |