PluginProbe
Booking for Appointments and Events Calendar – Amelia / 2.4
Booking for Appointments and Events Calendar – Amelia v2.4
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 All 59 releases
ameliabooking / src / Application / Commands / User / GetCurrentUserCommandHandler.php

GetCurrentUserCommandHandler.php in Booking for Appointments and Events Calendar – Amelia 2.4, at src/Application/Commands/User/GetCurrentUserCommandHandler.php

83 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User;
4
5 use AmeliaBooking\Application\Services\User\UserApplicationService;
6 use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException;
7 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
8 use AmeliaBooking\Domain\Entity\Entities;
9 use AmeliaBooking\Application\Commands\CommandResult;
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Domain\Entity\User\AbstractUser;
12 use AmeliaBooking\Domain\ValueObjects\String\Email;
13 use Exception;
14 use Interop\Container\Exception\ContainerException;
15 use Slim\Exception\ContainerValueNotFoundException;
16
17 /**
18 * Class GetCurrentUserCommandHandler
19 *
20 * @package AmeliaBooking\Application\Commands\User
21 */
22 class GetCurrentUserCommandHandler extends CommandHandler
23 {
24 /**
25 * @param GetCurrentUserCommand $command
26 *
27 * @return CommandResult
28 * @throws \Slim\Exception\ContainerException
29 * @throws \InvalidArgumentException
30 * @throws ContainerValueNotFoundException
31 * @throws InvalidArgumentException
32 * @throws ContainerException
33 * @throws Exception
34 */
35 public function handle(GetCurrentUserCommand $command)
36 {
37 $result = new CommandResult();
38
39 $this->checkMandatoryFields($command);
40
41 $userData = null;
42
43 if ($command->getToken()) {
44 /** @var UserApplicationService $userAS */
45 $userAS = $this->getContainer()->get('application.user.service');
46
47 try {
48 /** @var AbstractUser $user */
49 $user = $userAS->authorization(
50 $command->getToken(),
51 $command->getCabinetType() ? $command->getCabinetType() : 'customer'
52 );
53 } catch (AuthorizationException $e) {
54 $user = null;
55 }
56 } else {
57 /** @var AbstractUser $user */
58 $user = $this->getContainer()->get('logged.in.user');
59 }
60
61 if ($user && $user->getType() === 'customer' && !!$user->getExternalId() && !$user->getEmail()->getValue()) {
62 $wpUser = wp_get_current_user();
63 $user->setEmail(new Email($wpUser->user_email));
64 }
65
66 $userArray = $user ? $user->toArray() : null;
67
68 $userArray = apply_filters('amelia_get_current_user_filter', $userArray);
69
70 do_action('amelia_get_current_user', $userArray);
71
72 $result->setResult(CommandResult::RESULT_SUCCESS);
73 $result->setMessage('Successfully retrieved current user');
74 $result->setData(
75 [
76 Entities::USER => $userArray
77 ]
78 );
79
80 return $result;
81 }
82 }
83