PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.4
Booking for Appointments and Events Calendar – Amelia v1.2.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 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 / Customer / AddCustomerCommandHandler.php
ameliabooking / src / Application / Commands / User / Customer Last commit date
AddCustomerCommand.php 1 year ago AddCustomerCommandHandler.php 1 year ago GetCustomerCommand.php 1 year ago GetCustomerCommandHandler.php 1 year ago GetCustomersCommand.php 1 year ago GetCustomersCommandHandler.php 1 year ago UpdateCustomerCommand.php 1 year ago UpdateCustomerCommandHandler.php 1 year ago
AddCustomerCommandHandler.php
70 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User\Customer;
4
5 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
6 use AmeliaBooking\Application\Services\User\CustomerApplicationService;
7 use AmeliaBooking\Application\Services\User\UserApplicationService;
8 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
9 use AmeliaBooking\Domain\Entity\Entities;
10 use AmeliaBooking\Domain\Entity\User\AbstractUser;
11 use AmeliaBooking\Domain\Factory\User\UserFactory;
12 use AmeliaBooking\Application\Commands\CommandResult;
13 use AmeliaBooking\Application\Commands\CommandHandler;
14 use AmeliaBooking\Infrastructure\Repository\User\UserRepository;
15 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
16
17 /**
18 * Class AddCustomerCommandHandler
19 *
20 * @package AmeliaBooking\Application\Commands\User\Customer
21 */
22 class AddCustomerCommandHandler extends CommandHandler
23 {
24
25 public $mandatoryFields = [
26 'type',
27 'firstName',
28 'lastName',
29 'email'
30 ];
31
32 /**
33 * @param AddCustomerCommand $command
34 *
35 * @return CommandResult
36 * @throws \Slim\Exception\ContainerValueNotFoundException
37 * @throws AccessDeniedException
38 * @throws InvalidArgumentException
39 * @throws \AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException
40 * @throws \Interop\Container\Exception\ContainerException
41 */
42 public function handle(AddCustomerCommand $command)
43 {
44 if (!$command->getPermissionService()->currentUserCanWrite(Entities::CUSTOMERS)) {
45 throw new AccessDeniedException('You are not allowed to perform this action!');
46 }
47
48 /** @var CustomerApplicationService $customerAS */
49 $customerAS = $this->container->get('application.user.customer.service');
50
51 $this->checkMandatoryFields($command);
52
53 if ($command->getField('externalId') === -1) {
54 $command->setField('externalId', null);
55 }
56
57 $userData = $command->getFields();
58
59 $userData = apply_filters('amelia_before_customer_added_filter', $userData);
60
61 do_action('amelia_before_customer_added', $userData);
62
63 $response = $customerAS->createCustomer($userData);
64
65 do_action('amelia_after_customer_added', $response? $response->getData() : null);
66
67 return $response;
68 }
69 }
70