PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 2 days ago Provider 2 days ago DeleteUserCommand.php 1 year ago DeleteUserCommandHandler.php 1 year ago GetCurrentUserCommand.php 1 year ago GetCurrentUserCommandHandler.php 1 year ago GetUserDeleteEffectCommand.php 1 year ago GetUserDeleteEffectCommandHandler.php 6 months ago GetWPUsersCommand.php 1 year ago GetWPUsersCommandHandler.php 6 months ago
GetCurrentUserCommandHandler.php
83 lines
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