← All changes
|
src/Application/Commands/User/GetCurrentUserCommandHandler.php
+17
-6
trunk
→
2.4
View file →
| @@ -1,17 +1,19 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AmeliaBooking\Application\Commands\User; |
| 4 | 4 | |
| 5 | +use AmeliaBooking\Application\Services\User\UserApplicationService; | |
| 5 | 6 | use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException; |
| 6 | 7 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 7 | 8 | use AmeliaBooking\Domain\Entity\Entities; |
| 8 | 9 | use AmeliaBooking\Application\Commands\CommandResult; |
| 9 | 10 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 10 | -use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; | |
| 11 | 11 | use AmeliaBooking\Domain\Entity\User\AbstractUser; |
| 12 | 12 | use AmeliaBooking\Domain\ValueObjects\String\Email; |
| 13 | 13 | use Exception; |
| 14 | +use Interop\Container\Exception\ContainerException; | |
| 15 | +use Slim\Exception\ContainerValueNotFoundException; | |
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * Class GetCurrentUserCommandHandler |
| 17 | 19 | * |
| @@ -22,10 +24,13 @@ | ||
| 22 | 24 | /** |
| 23 | 25 | * @param GetCurrentUserCommand $command |
| 24 | 26 | * |
| 25 | 27 | * @return CommandResult |
| 28 | + * @throws \Slim\Exception\ContainerException | |
| 29 | + * @throws \InvalidArgumentException | |
| 30 | + * @throws ContainerValueNotFoundException | |
| 26 | 31 | * @throws InvalidArgumentException |
| 27 | - * @throws AccessDeniedException | |
| 32 | + * @throws ContainerException | |
| 28 | 33 | * @throws Exception |
| 29 | 34 | */ |
| 30 | 35 | public function handle(GetCurrentUserCommand $command) |
| 31 | 36 | { |
| @@ -32,16 +37,22 @@ | ||
| 32 | 37 | $result = new CommandResult(); |
| 33 | 38 | |
| 34 | 39 | $this->checkMandatoryFields($command); |
| 35 | 40 | |
| 41 | + $userData = null; | |
| 42 | + | |
| 36 | 43 | if ($command->getToken()) { |
| 44 | + /** @var UserApplicationService $userAS */ | |
| 45 | + $userAS = $this->getContainer()->get('application.user.service'); | |
| 46 | + | |
| 37 | 47 | try { |
| 38 | 48 | /** @var AbstractUser $user */ |
| 39 | - $user = $command->authorize(AbstractUser::USER_ROLE_CUSTOMER); | |
| 49 | + $user = $userAS->authorization( | |
| 50 | + $command->getToken(), | |
| 51 | + $command->getCabinetType() ? $command->getCabinetType() : 'customer' | |
| 52 | + ); | |
| 40 | 53 | } catch (AuthorizationException $e) { |
| 41 | 54 | $user = null; |
| 42 | - } catch (AccessDeniedException $e) { | |
| 43 | - $user = null; | |
| 44 | 55 | } |
| 45 | 56 | } else { |
| 46 | 57 | /** @var AbstractUser $user */ |
| 47 | 58 | $user = $this->getContainer()->get('logged.in.user'); |
| @@ -61,9 +72,9 @@ | ||
| 61 | 72 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 62 | 73 | $result->setMessage('Successfully retrieved current user'); |
| 63 | 74 | $result->setData( |
| 64 | 75 | [ |
| 65 | - Entities::USER => $userArray, | |
| 76 | + Entities::USER => $userArray | |
| 66 | 77 | ] |
| 67 | 78 | ); |
| 68 | 79 | |
| 69 | 80 | return $result; |