1 | <?php |
||
5 | abstract class Customization |
||
6 | { |
||
7 | /** |
||
8 | * Actual customization data. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $data = []; |
||
13 | |||
14 | /** |
||
15 | * Customization-related settings. |
||
16 | * |
||
17 | * @var SettingsManager |
||
18 | */ |
||
19 | protected $settings; |
||
20 | |||
21 | /** |
||
22 | * Creates groupped editables list. |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | abstract public function editables(); |
||
27 | |||
28 | /** |
||
29 | * Builds template data. |
||
30 | * |
||
31 | * @return mixed |
||
32 | */ |
||
33 | abstract public function build(); |
||
34 | |||
35 | /** |
||
36 | * Returns ['customization_name' => 'setting_key'] map. |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | public function settingsMap() |
||
46 | |||
47 | /** |
||
48 | * Triggers before the save settings operation. |
||
49 | */ |
||
50 | public function beforeSaving() |
||
54 | |||
55 | /** |
||
56 | * Saves customization settings. |
||
57 | * |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function save() |
||
68 | |||
69 | /** |
||
70 | * Returns value for given customization data key or default value. |
||
71 | * |
||
72 | * @param string $key |
||
73 | * @param mixed $defaultValue = null |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function get(string $key, $defaultValue = null) |
||
81 | |||
82 | /** |
||
83 | * Returns customization data. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function all() |
||
91 | |||
92 | /** |
||
93 | * Sets preview data. |
||
94 | * |
||
95 | * @param array $previewData |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function setPreviewData(array $previewData = []) |
||
115 | |||
116 | /** |
||
117 | * Sets settings manager. |
||
118 | * |
||
119 | * @param SettingsManager $settings |
||
120 | * |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function setSettings(SettingsManager $settings) |
||
129 | |||
130 | /** |
||
131 | * Renames customization keys to settings keys. |
||
132 | * |
||
133 | * @param array $previewData |
||
134 | * @param array $map |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | protected function renamePreviewDataKeys(array $previewData, array $map) |
||
151 | |||
152 | /** |
||
153 | * Returns value from preview data or default value. |
||
154 | * |
||
155 | * @param string $key |
||
156 | * @param null $defaultValue |
||
157 | * |
||
158 | * @return mixed|null |
||
159 | */ |
||
160 | protected function setting(string $key, $defaultValue = null) |
||
164 | |||
165 | /** |
||
166 | * Returns value from preview data or default value with replaced placeholders. |
||
167 | * |
||
168 | * @param string $key |
||
169 | * @param array $placeholders |
||
170 | * @param null $defaultValue |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function settingWithPlaceholders(string $key, array $placeholders = [], $defaultValue = null) |
||
180 | |||
181 | /** |
||
182 | * Creates new editables group. |
||
183 | * |
||
184 | * @param string $id |
||
185 | * @param string $title |
||
186 | * @param \Closure $settingsFactory |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | protected function group(string $id, string $title, \Closure $settingsFactory) |
||
198 | |||
199 | /** |
||
200 | * Creates new Editable. |
||
201 | * |
||
202 | * @param string $name |
||
203 | * @param string $type |
||
204 | * @param string|null $title |
||
205 | * @param null $value |
||
206 | * @param array $attributes |
||
207 | * |
||
208 | * @return Editable |
||
209 | */ |
||
210 | protected function editable(string $name, string $type, string $title = null, $value = null, array $attributes = []) |
||
218 | } |
||
219 |