PluginProbe
The Innovative Form Builder – IvyForms / 1.1.1
The Innovative Form Builder – IvyForms v1.1.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.1.1, at backend/src/Services/Integrations/IntegrationRegistry.php

114 lines 2.7 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 if (empty($config['component'])) {
40 throw new InvalidArgumentException("Integration '$slug' must have a component name");
41 }
42
43 // Merge with defaults
44 $this->integrations[$slug] = array_merge([
45 'slug' => $slug,
46 'icon' => 'integration',
47 'description' => '',
48 'requiresAuth' => false,
49 'hasFormSettings' => true,
50 'settingsSchema' => [],
51 'plan' => 'lite', // 'lite', 'essentials', 'growth', 'agency'
52 'learnMoreUrl' => '', // Optional documentation/learn more URL
53 ], $config);
54 }
55
56 /**
57 * Get all registered integrations
58 *
59 * @return mixed[]
60 */
61 public function getAll(): array
62 {
63 return $this->integrations;
64 }
65
66 /**
67 * Get a specific integration by slug
68 *
69 * @param string $slug
70 * @return mixed[]|null
71 */
72 public function get(string $slug): ?array
73 {
74 return $this->integrations[$slug] ?? null;
75 }
76
77 /**
78 * Check if an integration is registered
79 *
80 * @param string $slug
81 * @return bool
82 */
83 public function has(string $slug): bool
84 {
85 return isset($this->integrations[$slug]);
86 }
87
88 /**
89 * Get integrations by plan
90 *
91 * @param string|mixed[] $plans Plan name(s) to filter by
92 * @return mixed[]
93 */
94 public function getByPlan($plans): array
95 {
96 $plans = (array) $plans;
97
98 return array_filter($this->integrations, function ($integration) use ($plans) {
99 return in_array($integration['plan'], $plans);
100 });
101 }
102
103 /**
104 * Unregister an integration
105 *
106 * @param string $slug
107 * @return void
108 */
109 public function unregister(string $slug): void
110 {
111 unset($this->integrations[$slug]);
112 }
113 }
114