PluginProbe
The Innovative Form Builder – IvyForms / 1.4.1
The Innovative Form Builder – IvyForms v1.4.1
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
ivyforms / backend / src / Services / Integrations / IntegrationRegistry.php

IntegrationRegistry.php in The Innovative Form Builder – IvyForms 1.4.1, at backend/src/Services/Integrations/IntegrationRegistry.php

116 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Integrations;
4
5 use IvyForms\Common\Exceptions\InvalidArgumentException;
6
7 /**
8 * Integration Registry Service
9 *
10 * Central registry for all integrations (both Lite and Pro).
11 * Allows dynamic registration of integrations without hardcoding.
12 *
13 * @since 1.0.0
14 */
15 class IntegrationRegistry
16 {
17 /**
18 * Registered integrations
19 *
20 * @var mixed[]
21 */
22 private array $integrations = [];
23
24 /**
25 * Register an integration
26 *
27 * @param string $slug Integration slug (e.g., 'mailchimp', 'convertkit')
28 * @param mixed[] $config Integration configuration
29 * @return void
30 * @throws InvalidArgumentException
31 */
32 public function register(string $slug, array $config): void
33 {
34 // Validate required fields
35 if (empty($config['label'])) {
36 throw new InvalidArgumentException("Integration '$slug' must have a label");
37 }
38
39 // Documentation-only integrations have nothing to configure, so they have no settings component
40 if (empty($config['component']) && empty($config['docsOnly'])) {
41 throw new InvalidArgumentException("Integration '$slug' must have a component name");
42 }
43
44 // Merge with defaults
45 $this->integrations[$slug] = array_merge([
46 'slug' => $slug,
47 'icon' => 'integration',
48 'description' => '',
49 'requiresAuth' => false,
50 'hasFormSettings' => true,
51 'settingsSchema' => [],
52 'plan' => 'lite', // 'lite', 'essentials', 'growth', 'agency'
53 'learnMoreUrl' => '', // Optional documentation/learn more URL
54 'docsOnly' => false, // Card shows only a "Learn more" link — no toggle, no settings
55 ], $config);
56 }
57
58 /**
59 * Get all registered integrations
60 *
61 * @return mixed[]
62 */
63 public function getAll(): array
64 {
65 return $this->integrations;
66 }
67
68 /**
69 * Get a specific integration by slug
70 *
71 * @param string $slug
72 * @return mixed[]|null
73 */
74 public function get(string $slug): ?array
75 {
76 return $this->integrations[$slug] ?? null;
77 }
78
79 /**
80 * Check if an integration is registered
81 *
82 * @param string $slug
83 * @return bool
84 */
85 public function has(string $slug): bool
86 {
87 return isset($this->integrations[$slug]);
88 }
89
90 /**
91 * Get integrations by plan
92 *
93 * @param string|mixed[] $plans Plan name(s) to filter by
94 * @return mixed[]
95 */
96 public function getByPlan($plans): array
97 {
98 $plans = (array) $plans;
99
100 return array_filter($this->integrations, function ($integration) use ($plans) {
101 return in_array($integration['plan'], $plans);
102 });
103 }
104
105 /**
106 * Unregister an integration
107 *
108 * @param string $slug
109 * @return void
110 */
111 public function unregister(string $slug): void
112 {
113 unset($this->integrations[$slug]);
114 }
115 }
116