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 / ValueObjects / Form / IntegrationSettings.php

IntegrationSettings.php in The Innovative Form Builder – IvyForms 1.4.1, at backend/src/ValueObjects/Form/IntegrationSettings.php

98 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\ValueObjects\Form;
4
5 use IvyForms\Services\Template\TemplateDefaults;
6
7 /**
8 * Class IntegrationSettings
9 * Encapsulates integration settings for a form.
10 *
11 * @property array<string, array<string, mixed>> $settings
12 */
13 final class IntegrationSettings
14 {
15 /**
16 * @var array<string, array<string, mixed>>
17 */
18 private array $settings = [];
19
20 /**
21 * IntegrationSettings constructor.
22 * @param array<string, array<string, mixed>>|null $settings
23 */
24 public function __construct($settings = null)
25 {
26 if (!is_array($settings) || empty($settings)) {
27 $settings = TemplateDefaults::getDefaultIntegrationSettings();
28 }
29 $this->settings = $settings;
30 }
31
32 /**
33 * Get settings for a specific integration.
34 * @param string $integration
35 * @return array<string, mixed>|null
36 */
37 public function get(string $integration): ?array
38 {
39 return $this->settings[$integration] ?? null;
40 }
41
42 /**
43 * Set settings for a specific integration.
44 * @param string $integration
45 * @param array<string, mixed> $settings
46 */
47 public function set(string $integration, array $settings): void
48 {
49 $this->settings[$integration] = $settings;
50 }
51
52 /**
53 * Get all integration settings.
54 * @return array<string, array<string, mixed>>
55 */
56 public function getAll(): array
57 {
58 if (empty($this->settings)) {
59 return TemplateDefaults::getDefaultIntegrationSettings();
60 }
61 return $this->settings;
62 }
63
64 /**
65 * Get enabled status for any integration.
66 * @param string $integration
67 * @return bool
68 */
69 public function isIntegrationEnabled(string $integration): bool
70 {
71 return !empty($this->settings[$integration]['enabled']);
72 }
73
74 /**
75 * Set enabled status for any integration.
76 * @param string $integration
77 * @param bool $enabled
78 */
79 public function setIntegrationEnabled(string $integration, bool $enabled): void
80 {
81 if (!isset($this->settings[$integration])) {
82 $this->settings[$integration] = [];
83 }
84 $this->settings[$integration]['enabled'] = $enabled;
85 }
86
87 /**
88 * Export settings as array.
89 * @return array<string, array<string, mixed>>
90 */
91 public function toArray(): array
92 {
93 return [
94 'integrationSettings' => $this->settings
95 ];
96 }
97 }
98