PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Controllers / Confirmation / UpdateConfirmationController.php

UpdateConfirmationController.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Controllers/Confirmation/UpdateConfirmationController.php

77 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Controllers\Confirmation;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Exceptions\QueryExecutionException;
13 use IvyForms\Common\Exceptions\ValidationException;
14 use IvyForms\Common\Sanitizer\Sanitizer;
15 use IvyForms\Controllers\Controller;
16 use IvyForms\Factory\Confirmation\ConfirmationFactory;
17 use IvyForms\Services\Confirmation\ConfirmationService;
18 use IvyForms\Services\Translations\BackendStrings;
19 use WP_REST_Request;
20 use WP_REST_Response;
21
22 /**
23 * Class UpdateConfirmationController
24 *
25 * @package IvyForms\Controllers\Confirmation
26 */
27 class UpdateConfirmationController extends Controller
28 {
29 private ConfirmationService $confirmationService;
30
31 public function __construct(ConfirmationService $confirmationService)
32 {
33 $this->confirmationService = $confirmationService;
34 }
35
36 /**
37 * @param WP_REST_Request $data
38 *
39 * @return WP_REST_Response
40 *
41 * @throws QueryExecutionException
42 * @throws InvalidArgumentException
43 * @throws ForbiddenException
44 * @throws ValidationException
45 */
46 public function handle(WP_REST_Request $data): WP_REST_Response
47 {
48 // Verify the nonce
49 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
50 // Validate and sanitize input data
51 if (empty($data->get_params())) {
52 throw new InvalidArgumentException(
53 BackendStrings::getExceptionStrings()['invalid_request_data']
54 );
55 }
56
57 $params = Sanitizer::sanitizeConfirmationData($data->get_params());
58
59 $confirmation = ConfirmationFactory::create($params);
60
61 $confirmationId = $confirmation->getId();
62
63 $this->confirmationService->updateConfirmation($confirmationId, $confirmation);
64
65 if (!$confirmation->getId()) {
66 throw new QueryExecutionException(
67 BackendStrings::getSettingsFormBuilderStrings()['failed_to_update_confirmation'] . '.'
68 );
69 }
70
71 return new WP_REST_Response([
72 'message' => BackendStrings::getCommonStrings()['ok'],
73 'data' => $confirmation->toArray()
74 ], 200);
75 }
76 }
77