PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 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 All 27 releases
← All changes | backend/src/Controllers/Confirmation/GetConformationController.php +57 -0 0.6.1 → 1.5 View file →
@@ -1,0 +1,57 @@
1 +<?php
2 +
3 +namespace IvyForms\Controllers\Confirmation;
4 +
5 +use IvyForms\Common\Exceptions\ForbiddenException;
6 +use IvyForms\Common\Exceptions\InvalidArgumentException;
7 +use IvyForms\Common\Exceptions\NotFoundException;
8 +use IvyForms\Common\Sanitizer\Sanitizer;
9 +use IvyForms\Controllers\Controller;
10 +use IvyForms\Services\Confirmation\ConfirmationService;
11 +use IvyForms\Services\Translations\BackendStrings;
12 +use WP_REST_Request;
13 +use WP_REST_Response;
14 +
15 +/**
16 + * Class GetConformationController
17 + *
18 + * @package IvyForms\Controllers\Confirmation
19 + */
20 +class GetConformationController extends Controller
21 +{
22 + private ConfirmationService $confirmationService;
23 +
24 + public function __construct(ConfirmationService $confirmationService)
25 + {
26 + $this->confirmationService = $confirmationService;
27 + }
28 +
29 + /**
30 + * @param WP_REST_Request $data
31 + *
32 + * @return WP_REST_Response
33 + *
34 + * @throws InvalidArgumentException
35 + * @throws NotFoundException
36 + * @throws ForbiddenException
37 + */
38 + public function handle(WP_REST_Request $data): WP_REST_Response
39 + {
40 + // Verify the nonce
41 + Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
42 + $confirmationId = Sanitizer::sanitizeId($data->get_param('id'));
43 +
44 + if (empty($confirmationId)) {
45 + throw new InvalidArgumentException(
46 + BackendStrings::getExceptionStrings()['confirmation_id_required']
47 + );
48 + }
49 +
50 + $confirmation = $this->confirmationService->getConfirmationById($confirmationId);
51 +
52 + return new WP_REST_Response([
53 + 'message' => BackendStrings::getCommonStrings()['ok'],
54 + 'data' => $confirmation->toArray()
55 + ], 200);
56 + }
57 +}