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

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

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