1 | <?php |
||
5 | abstract class Customization |
||
6 | { |
||
7 | /** |
||
8 | * Actual customization data. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $data = []; |
||
13 | |||
14 | /** |
||
15 | * Preview data. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $previewData = []; |
||
20 | |||
21 | /** |
||
22 | * Customization-related settings. |
||
23 | * |
||
24 | * @var SettingsManager |
||
25 | */ |
||
26 | protected $settings; |
||
27 | |||
28 | /** |
||
29 | * Creates groupped editables list. |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | abstract public function editables(); |
||
34 | |||
35 | /** |
||
36 | * Builds template data. |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | abstract public function build(); |
||
41 | |||
42 | /** |
||
43 | * Returns ['customization_name' => 'setting_key'] map. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function settingsMap() |
||
53 | |||
54 | /** |
||
55 | * Triggers before the save settings operation. |
||
56 | */ |
||
57 | public function beforeSaving() |
||
61 | |||
62 | /** |
||
63 | * Saves customization settings. |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function save() |
||
75 | |||
76 | /** |
||
77 | * Returns customization data. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | public function all() |
||
85 | |||
86 | /** |
||
87 | * Sets preview data. |
||
88 | * |
||
89 | * @param array $previewData |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | public function setPreviewData(array $previewData = []) |
||
109 | |||
110 | /** |
||
111 | * Sets settings manager. |
||
112 | * |
||
113 | * @param SettingsManager $settings |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function setSettings(SettingsManager $settings) |
||
123 | |||
124 | /** |
||
125 | * Renames customization keys to settings keys. |
||
126 | * |
||
127 | * @param array $previewData |
||
128 | * @param array $map |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | protected function renamePreviewDataKeys(array $previewData, array $map) |
||
145 | |||
146 | /** |
||
147 | * Returns value from preview data or default value. |
||
148 | * |
||
149 | * @param string $key |
||
150 | * @param null $defaultValue |
||
151 | * |
||
152 | * @return mixed|null |
||
153 | */ |
||
154 | protected function setting(string $key, $defaultValue = null) |
||
158 | |||
159 | /** |
||
160 | * Returns value from preview data or default value with replaced placeholders. |
||
161 | * |
||
162 | * @param string $key |
||
163 | * @param array $placeholders |
||
164 | * @param null $defaultValue |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | protected function settingWithPlaceholders(string $key, array $placeholders = [], $defaultValue = null) |
||
174 | |||
175 | /** |
||
176 | * Creates new editables group. |
||
177 | * |
||
178 | * @param string $id |
||
179 | * @param string $title |
||
180 | * @param \Closure $settingsFactory |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | protected function group(string $id, string $title, \Closure $settingsFactory) |
||
192 | |||
193 | /** |
||
194 | * Creates new Editable. |
||
195 | * |
||
196 | * @param string $name |
||
197 | * @param string $type |
||
198 | * @param string|null $title |
||
199 | * @param null $value |
||
200 | * @param array $attributes |
||
201 | * |
||
202 | * @return Editable |
||
203 | */ |
||
204 | protected function editable(string $name, string $type, string $title = null, $value = null, array $attributes = []) |
||
212 | } |
||
213 |