| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\ValueObjects\Form; |
| 4 |
|
| 5 |
// phpcs:disable PSR1.Files.SideEffects |
| 6 |
use IvyForms\Services\Template\TemplateDefaults; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; // Exit if accessed directly |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Encapsulates form style settings (quick/advanced mode, themes, classes). |
| 14 |
* |
| 15 |
* @property array<string, mixed> $settings |
| 16 |
*/ |
| 17 |
final class StyleSettings |
| 18 |
{ |
| 19 |
/** |
| 20 |
* @var array<string, mixed> |
| 21 |
*/ |
| 22 |
private array $settings = []; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param array<string, mixed>|null $settings Parsed style settings or null. |
| 26 |
*/ |
| 27 |
public function __construct($settings = null) |
| 28 |
{ |
| 29 |
$defaults = TemplateDefaults::getDefaultFormStylesSafe(); |
| 30 |
|
| 31 |
if (!is_array($settings) || !array_key_exists('stylesEnabled', $settings)) { |
| 32 |
$this->settings = $defaults; |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$this->settings = array_replace_recursive($defaults, $settings); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Full style settings tree (non-null after construction). |
| 41 |
* |
| 42 |
* @return array<string, mixed> |
| 43 |
*/ |
| 44 |
public function getAll(): array |
| 45 |
{ |
| 46 |
return $this->settings; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Export for persistence / array merges (same key as API and DB column). |
| 51 |
* |
| 52 |
* @return array{styleSettings: array<string, mixed>} |
| 53 |
*/ |
| 54 |
public function toArray(): array |
| 55 |
{ |
| 56 |
return [ |
| 57 |
'styleSettings' => $this->settings, |
| 58 |
]; |
| 59 |
} |
| 60 |
} |
| 61 |
|