| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © Melograno Venture Studio. All rights reserved. |
| 5 |
* @licence See LICENCE.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace IvyForms\Services\Form\Style; |
| 9 |
|
| 10 |
// phpcs:disable PSR1.Files.SideEffects |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; // Exit if accessed directly |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Class StyleContext |
| 18 |
* |
| 19 |
* Value object holding all data that style generators may need. |
| 20 |
* Generators read only the fields they require. |
| 21 |
* |
| 22 |
* @package IvyForms\Common\Helpers\StyleHelpers |
| 23 |
*/ |
| 24 |
final class StyleContext |
| 25 |
{ |
| 26 |
/** |
| 27 |
* Base CSS selector (e.g. ".ivyforms-form-wrapper-5.custom-class") |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
private string $baseSelector; |
| 32 |
|
| 33 |
/** |
| 34 |
* Inner wrapper CSS selector (e.g. ".ivyforms-form-wrapper.ivyforms-form-wrapper-5") |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
private string $innerWrapperSelector; |
| 39 |
|
| 40 |
/** |
| 41 |
* Form element CSS selector (e.g. ".ivyforms-form-5") |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
private string $formSelector; |
| 46 |
|
| 47 |
/** |
| 48 |
* Form ID for the form being styled |
| 49 |
* |
| 50 |
* @var int |
| 51 |
*/ |
| 52 |
private int $formId; |
| 53 |
|
| 54 |
/** |
| 55 |
* Active colors extracted from style settings |
| 56 |
* |
| 57 |
* @var array<string, string> |
| 58 |
*/ |
| 59 |
private array $activeColors; |
| 60 |
|
| 61 |
/** |
| 62 |
* Active styles extracted from style settings |
| 63 |
* |
| 64 |
* @var array<string, string> |
| 65 |
*/ |
| 66 |
private array $activeStyles; |
| 67 |
|
| 68 |
/** |
| 69 |
* Raw style settings array |
| 70 |
* |
| 71 |
* @var array<string, mixed> |
| 72 |
*/ |
| 73 |
private array $styleSettings; |
| 74 |
|
| 75 |
/** |
| 76 |
* Constructor |
| 77 |
* |
| 78 |
* @param string $baseSelector |
| 79 |
* @param string $innerWrapperSelector |
| 80 |
* @param string $formSelector |
| 81 |
* @param int $formId |
| 82 |
* @param array<string, string> $activeColors |
| 83 |
* @param array<string, string> $activeStyles |
| 84 |
* @param array<string, mixed> $styleSettings |
| 85 |
*/ |
| 86 |
public function __construct( |
| 87 |
string $baseSelector, |
| 88 |
string $innerWrapperSelector, |
| 89 |
string $formSelector, |
| 90 |
int $formId, |
| 91 |
array $activeColors, |
| 92 |
array $activeStyles, |
| 93 |
array $styleSettings |
| 94 |
) { |
| 95 |
$this->baseSelector = $baseSelector; |
| 96 |
$this->innerWrapperSelector = $innerWrapperSelector; |
| 97 |
$this->formSelector = $formSelector; |
| 98 |
$this->formId = $formId; |
| 99 |
$this->activeColors = $activeColors; |
| 100 |
$this->activeStyles = $activeStyles; |
| 101 |
$this->styleSettings = $styleSettings; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Get base CSS selector |
| 106 |
* |
| 107 |
* @return string |
| 108 |
*/ |
| 109 |
public function getBaseSelector(): string |
| 110 |
{ |
| 111 |
return $this->baseSelector; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get inner wrapper CSS selector |
| 116 |
* |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
public function getInnerWrapperSelector(): string |
| 120 |
{ |
| 121 |
return $this->innerWrapperSelector; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Get form element CSS selector |
| 126 |
* |
| 127 |
* @return string |
| 128 |
*/ |
| 129 |
public function getFormSelector(): string |
| 130 |
{ |
| 131 |
return $this->formSelector; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Get form ID |
| 136 |
* |
| 137 |
* @return int |
| 138 |
*/ |
| 139 |
public function getFormId(): int |
| 140 |
{ |
| 141 |
return $this->formId; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Get active colors |
| 146 |
* |
| 147 |
* @return array<string, string> |
| 148 |
*/ |
| 149 |
public function getActiveColors(): array |
| 150 |
{ |
| 151 |
return $this->activeColors; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Get active styles |
| 156 |
* |
| 157 |
* @return array<string, string> |
| 158 |
*/ |
| 159 |
public function getActiveStyles(): array |
| 160 |
{ |
| 161 |
return $this->activeStyles; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Get raw style settings |
| 166 |
* |
| 167 |
* @return array<string, mixed> |
| 168 |
*/ |
| 169 |
public function getStyleSettings(): array |
| 170 |
{ |
| 171 |
return $this->styleSettings; |
| 172 |
} |
| 173 |
} |
| 174 |
|