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
ivyforms / backend / src / Services / Integrations / IntegrationRegistry.php

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

117 lines 3.0 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 'comingSoon' => false, // Card shows a "Coming soon" badge — no toggle, no button, no settings
56 ], $config);
57 }
58
59 /**
60 * Get all registered integrations
61 *
62 * @return mixed[]
63 */
64 public function getAll(): array
65 {
66 return $this->integrations;
67 }
68
69 /**
70 * Get a specific integration by slug
71 *
72 * @param string $slug
73 * @return mixed[]|null
74 */
75 public function get(string $slug): ?array
76 {
77 return $this->integrations[$slug] ?? null;
78 }
79
80 /**
81 * Check if an integration is registered
82 *
83 * @param string $slug
84 * @return bool
85 */
86 public function has(string $slug): bool
87 {
88 return isset($this->integrations[$slug]);
89 }
90
91 /**
92 * Get integrations by plan
93 *
94 * @param string|mixed[] $plans Plan name(s) to filter by
95 * @return mixed[]
96 */
97 public function getByPlan($plans): array
98 {
99 $plans = (array) $plans;
100
101 return array_filter($this->integrations, function ($integration) use ($plans) {
102 return in_array($integration['plan'], $plans);
103 });
104 }
105
106 /**
107 * Unregister an integration
108 *
109 * @param string $slug
110 * @return void
111 */
112 public function unregister(string $slug): void
113 {
114 unset($this->integrations[$slug]);
115 }
116 }
117