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 / Integration / GetIntegrationController.php

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

64 lines 1.6 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\Integration;
4
5 use IvyForms\Common\Exceptions\ForbiddenException;
6 use IvyForms\Common\Sanitizer\Sanitizer;
7 use IvyForms\Controllers\Controller;
8 use IvyForms\Services\Integrations\IntegrationRegistry;
9 use WP_REST_Request;
10 use WP_REST_Response;
11
12 /**
13 * Get Single Integration Controller
14 *
15 * Returns a specific integration by slug
16 *
17 * @since 1.0.0
18 */
19 class GetIntegrationController extends Controller
20 {
21 private IntegrationRegistry $registry;
22
23 public function __construct(IntegrationRegistry $registry)
24 {
25 $this->registry = $registry;
26 }
27
28 /**
29 * Handle the request
30 *
31 * @param WP_REST_Request<array<string, mixed>> $data
32 * @return WP_REST_Response
33 * @throws ForbiddenException
34 */
35 public function handle(WP_REST_Request $data): WP_REST_Response
36 {
37 // Verify the nonce
38 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
39
40 $slug = Sanitizer::sanitizeText($data->get_param('slug'));
41
42 if (empty($slug)) {
43 return new WP_REST_Response([
44 'success' => false,
45 'message' => __('Integration slug is required', 'ivyforms'),
46 ], 400);
47 }
48
49 $integration = $this->registry->get($slug);
50
51 if (!$integration) {
52 return new WP_REST_Response([
53 'success' => false,
54 'message' => sprintf(__('Integration "%s" not found', 'ivyforms'), $slug),
55 ], 404);
56 }
57
58 return new WP_REST_Response([
59 'success' => true,
60 'data' => $integration,
61 ], 200);
62 }
63 }
64