PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
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 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / User / GetCurrentUserCommandHandler.php
ameliabooking / src / Application / Commands / User Last commit date
Customer 1 week ago Provider 1 week ago DeleteUserCommand.php 1 year ago DeleteUserCommandHandler.php 1 year ago GetCurrentUserCommand.php 1 year ago GetCurrentUserCommandHandler.php 1 week ago GetUserDeleteEffectCommand.php 1 year ago GetUserDeleteEffectCommandHandler.php 7 months ago GetWPUsersCommand.php 1 year ago GetWPUsersCommandHandler.php 7 months ago
GetCurrentUserCommandHandler.php
72 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User;
4
5 use AmeliaBooking\Domain\Common\Exceptions\AuthorizationException;
6 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
7 use AmeliaBooking\Domain\Entity\Entities;
8 use AmeliaBooking\Application\Commands\CommandResult;
9 use AmeliaBooking\Application\Commands\CommandHandler;
10 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
11 use AmeliaBooking\Domain\Entity\User\AbstractUser;
12 use AmeliaBooking\Domain\ValueObjects\String\Email;
13 use Exception;
14
15 /**
16 * Class GetCurrentUserCommandHandler
17 *
18 * @package AmeliaBooking\Application\Commands\User
19 */
20 class GetCurrentUserCommandHandler extends CommandHandler
21 {
22 /**
23 * @param GetCurrentUserCommand $command
24 *
25 * @return CommandResult
26 * @throws InvalidArgumentException
27 * @throws AccessDeniedException
28 * @throws Exception
29 */
30 public function handle(GetCurrentUserCommand $command)
31 {
32 $result = new CommandResult();
33
34 $this->checkMandatoryFields($command);
35
36 if ($command->getToken()) {
37 try {
38 /** @var AbstractUser $user */
39 $user = $command->authorize(AbstractUser::USER_ROLE_CUSTOMER);
40 } catch (AuthorizationException $e) {
41 $user = null;
42 } catch (AccessDeniedException $e) {
43 $user = null;
44 }
45 } else {
46 /** @var AbstractUser $user */
47 $user = $this->getContainer()->get('logged.in.user');
48 }
49
50 if ($user && $user->getType() === 'customer' && !!$user->getExternalId() && !$user->getEmail()->getValue()) {
51 $wpUser = wp_get_current_user();
52 $user->setEmail(new Email($wpUser->user_email));
53 }
54
55 $userArray = $user ? $user->toArray() : null;
56
57 $userArray = apply_filters('amelia_get_current_user_filter', $userArray);
58
59 do_action('amelia_get_current_user', $userArray);
60
61 $result->setResult(CommandResult::RESULT_SUCCESS);
62 $result->setMessage('Successfully retrieved current user');
63 $result->setData(
64 [
65 Entities::USER => $userArray,
66 ]
67 );
68
69 return $result;
70 }
71 }
72