-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
131 lines (121 loc) · 4.07 KB
/
Copy pathcode.power
File metadata and controls
131 lines (121 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Search Config
*
* @var Config
* @since 3.2.0
*/
protected Config $config;
/**
* Constructor
*
* @param Config|null $config The search config object.
* @param Table|null $table The search table object.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Table $table = null)
{
parent::__construct($table ?? Factory::_('Table'));
$this->config = $config ?: Factory::_('Config');
}
/**
* Model the value
* Example: $this->value(value, 'value_key', 'table_name');
*
* @param mixed $value The value to model
* @param string $field The field key
* @param string|null $table The table
*
* @return mixed
* @since 3.2.0
*/
public function value($value, string $field, ?string $table = null)
{
// load the table
if (empty($table))
{
$table = $this->getTable();
}
// check if this is a valid table
if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null)
{
// open the value based on the store method
switch($store)
{
case 'base64':
$value = base64_decode((string) $value);
break;
case 'json':
// check if there is a json string
if (JsonHelper::check($value))
{
$value = json_decode((string) $value, true);
}
break;
}
}
return $value;
}
/**
* Validate before the value is modelled (basic, override in child class)
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
{
return true;
}
/**
* Validate after the value is modelled (basic, override in child class)
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
{
// Start note to self
// Yes we don't search in the field->xml (field) PHP because the xml is messy
// first of all we need to change that storage method :((( seriously
// and the actual PHP is stored in the xml as base64 with a [__.o0=base64=Oo.__] key in front of it
// if I can go back and drag you around by your ear... I will, but okay you did not know better.
// Listen you have tried to fix this a few times already (I lost count) and by the time you realize how it works
// two hours have been wasted, and you usually only then realize why it's not fixed in the first place... o boy... just walk now!
// since unless you have three days don't even look further, this is a huge issue/mess
// and while I agree it needs fixing, it will not take a few hours... but days
// End note to self
// check values
if (StringHelper::check($value) || ArrayHelper::check($value, true))
{
return true;
}
// remove empty values
return false;
// Start another note to self
// If you're still here
// the problem is not opening the PHP in the xml,
// it is storing it with the updated changes... if any are made via the search-update methods
// so the only way to fix this is to change the whole way the xml values in the field table is stored.
// Yes, that is right... all the way back to the field view... and then to update all places you open that xml values
// and get the values out of the xml string and use them, and if you've forgotten, that is nearly everywhere,
// and so let the refactoring of the foundation begin... there I saved you another 3 hours.
// End another note to self
}
/**
* Get the current active table
*
* @return string
* @since 3.2.0
*/
protected function getTable(): string
{
return $this->config->table_name;
}