PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Setting / Encoder.php
codepress-admin-columns / classes / Setting Last commit date
ComponentFactory 3 days ago Control 3 days ago Type 3 days ago AttributeCollection.php 3 days ago AttributeFactory.php 3 days ago Children.php 3 days ago Component.php 3 days ago ComponentBuilder.php 3 days ago ComponentCollection.php 3 days ago ComponentFactory.php 3 days ago ConditionalComponentFactory.php 3 days ago ConditionalComponentFactoryCollection.php 3 days ago Config.php 3 days ago ConfigCollection.php 3 days ago ConfigFactory.php 3 days ago Context.php 3 days ago Control.php 3 days ago DefaultSettingsBuilder.php 3 days ago Encoder.php 3 days ago Formatter.php 3 days ago FormatterCollection.php 3 days ago
Encoder.php
131 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Setting;
6
7 use AC\Setting\Control\Input\Custom;
8 use AC\Setting\Control\Input\Number;
9 use AC\Setting\Control\Input\Open;
10 use AC\Setting\Control\Input\Option;
11 use AC\Setting\Control\OptionCollection;
12
13 final class Encoder
14 {
15 private ComponentCollection $settings;
16
17 public function __construct(ComponentCollection $settings)
18 {
19 $this->settings = $settings;
20 }
21
22 public function encode(): array
23 {
24 $encoded = [];
25
26 foreach ($this->settings as $setting) {
27 $encoded[] = $this->encode_setting($setting);
28 }
29
30 return $encoded;
31 }
32
33 private function encode_setting(Component $component): array
34 {
35 $encoded = [
36 'type' => $component->get_type(),
37 'label' => $component->has_label() ? $component->get_label() : '',
38 ];
39
40 if ($component->has_description()) {
41 $encoded['description'] = $component->get_description();
42 }
43
44 foreach ($component->get_attributes() as $attribute) {
45 $encoded['attributes'][$attribute->get_name()] = $attribute->get_value();
46 }
47
48 if ($component->has_input()) {
49 $input = $component->get_input();
50
51 $encoded['conditions'] = $component->get_conditions()->export();
52
53 $encoded['input'] = [
54 'type' => $input->get_type(),
55 'name' => $input->get_name(),
56 ];
57
58 if ($input->has_placeholder()) {
59 $encoded['input']['placeholder'] = $input->get_placeholder();
60 }
61
62 foreach ($input->get_attributes() as $attribute) {
63 $encoded['input']['attributes'][$attribute->get_name()] = $attribute->get_value();
64 }
65
66 if ($input->has_value()) {
67 $encoded['input']['default'] = $input->get_value();
68 }
69
70 if ($input instanceof Open && $input->has_append()) {
71 $encoded['input']['append'] = $input->get_append();
72 }
73
74 if ($input instanceof Option) {
75 $encoded['input'] += [
76 'options' => $this->encode_options($input->get_options()),
77 ];
78
79 if ($input->is_multiple()) {
80 $encoded['input']['type'] = 'select_multiple';
81 }
82 }
83
84 if ($input instanceof Number) {
85 if ($input->has_min()) {
86 $encoded['input']['min'] = $input->get_min();
87 }
88
89 if ($input->has_max()) {
90 $encoded['input']['max'] = $input->get_max();
91 }
92
93 if ($input->has_step()) {
94 $encoded['input']['step'] = $input->get_step();
95 }
96 }
97
98 if ($input instanceof Custom) {
99 $encoded['input']['data'] = $input->get_data();
100 }
101 }
102
103 if ($component->has_children()) {
104 $encoded['is_parent'] = $component->get_children()->is_parent();
105 $encoded['children'] = [];
106
107 foreach ($component->get_children()->get_iterator() as $item) {
108 $encoded['children'][] = $this->encode_setting($item);
109 }
110 }
111
112 return $encoded;
113 }
114
115 private function encode_options(OptionCollection $options): array
116 {
117 $encoded = [];
118
119 foreach ($options as $option) {
120 $encoded[] = [
121 'value' => $option->get_value(),
122 'label' => $option->get_label(),
123 'group' => $option->get_group(),
124 ];
125 }
126
127 return $encoded;
128 }
129
130 }
131