Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentform/app/Modules/Form/FormFieldsParser.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentForm\App\Modules\Form;
4
+
5
+
use FluentForm\App\Services\Parser\Form as FormParser;
6
+
7
+
/**
8
+
* Available methods
9
+
*
10
+
* @method static array getShortCodeInputs(\stdClass $form, array $with = ['admin_label'])
11
+
* @method static array getValidations(\stdClass $form, array $inputs, array $fields = [])
12
+
* @method static array getElement(\stdClass $form, string|array $name, array $with = [])
13
+
* @method static boolean hasElement(\stdClass $form, string $name)
14
+
* @method static boolean hasPaymentFields(\stdClass $form)
15
+
* @method static array getPaymentFields(\stdClass $form, $with = [])
16
+
* @method static array getPaymentInputFields(\stdClass $form, $with = [])
17
+
* @method static array getAttachmentInputFields(\stdClass $form, $with = [])
18
+
* @method static boolean hasRequiredFields(\stdClass $form, array $fields)
19
+
* @method static array getInputsByElementTypes(\stdClass $form, array $elements, array $with = [])
20
+
* @method static array|null getField(\stdClass $form, string|array $element, string|array $attribute, array $with = [])
21
+
* @method static array getEssentialInputs(\stdClass $form, array $inputs, array $with)
22
+
*/
23
+
class FormFieldsParser
24
+
{
25
+
protected static $forms = [];
26
+
27
+
protected static $formsWith = [];
28
+
29
+
public static function maybeResetForm($form, $with)
30
+
{
31
+
if (!is_object($form) && is_numeric($form)) {
32
+
$form = \FluentForm\App\Models\Form::find($form);
33
+
}
34
+
35
+
if (isset(static::$formsWith[$form->id]) && array_diff(static::$formsWith[$form->id], $with)) {
36
+
static::$forms[$form->id] = [];
37
+
}
38
+
static::$formsWith[$form->id] = $with;
39
+
}
40
+
41
+
public static function getFields($form, $asArray = false)
42
+
{
43
+
return static::parse('fields', $form, $asArray);
44
+
}
45
+
46
+
public static function getInputs($form, $with = [])
47
+
{
48
+
static::maybeResetForm($form, $with);
49
+
return static::parse('inputs', $form, $with);
50
+
}
51
+
52
+
public static function getEntryInputs($form, $with = ['admin_label', 'raw'])
53
+
{
54
+
static::maybeResetForm($form, $with);
55
+
return static::parse('entry_inputs', $form, $with);
56
+
}
57
+
58
+
public static function parse($key, $form, $with)
59
+
{
60
+
if (!is_object($form) && is_numeric($form)) {
61
+
$form = wpFluent()->table('fluentform_forms')->find($form);
62
+
}
63
+
64
+
// Return empty array if form is still not found or is null
65
+
if (!$form || !is_object($form)) {
66
+
return [];
67
+
}
68
+
69
+
if (!isset(static::$forms[$form->id])) {
70
+
static::$forms[$form->id] = [];
71
+
}
72
+
73
+
if (!isset(static::$forms[$form->id][$key])) {
74
+
$parser = new FormParser($form);
75
+
$method = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
76
+
77
+
static::$forms[$form->id][$key] = $parser->{'get' . $method}($with);
78
+
}
79
+
80
+
return static::$forms[$form->id][$key];
81
+
}
82
+
83
+
public static function getAdminLabels($form, $fields = [])
84
+
{
85
+
if (!isset(static::$forms[$form->id])) {
86
+
static::$forms[$form->id] = [];
87
+
}
88
+
89
+
if (!isset(static::$forms[$form->id]['admin_labels'])) {
90
+
$parser = new FormParser($form);
91
+
static::$forms[$form->id]['admin_labels'] = $parser->getAdminLabels($fields);
92
+
}
93
+
94
+
return static::$forms[$form->id]['admin_labels'];
95
+
}
96
+
97
+
/**
98
+
* Deligate dynamic static method calls to FormParser method.
99
+
* And set the result to the store before returning to dev.
100
+
*
101
+
* @param string $method
102
+
* @param array $parameters
103
+
*
104
+
* @return mixed
105
+
*/
106
+
public static function __callStatic($method, $parameters)
107
+
{
108
+
// The first item of the parameters is expected to contain the form object.
109
+
$form = array_shift($parameters);
110
+
111
+
$forceFreshValue = [
112
+
'getField',
113
+
'getElement',
114
+
'hasElement',
115
+
'getInputsByElementTypes',
116
+
];
117
+
118
+
// If the store doesn't have the requested result we'll
119
+
// deletegate the method call to the Parser method.
120
+
// Set the store before returning it to the dev.
121
+
if (in_array($method, $forceFreshValue) || !isset(static::$forms[$form->id][$method])) {
122
+
$parser = new FormParser($form);
123
+
124
+
static::$forms[$form->id][$method] = call_user_func_array([$parser, $method], $parameters);
125
+
}
126
+
127
+
return static::$forms[$form->id][$method];
128
+
}
129
+
130
+
public static function resetData()
131
+
{
132
+
static::$forms = [];
133
+
static::$formsWith = [];
134
+
}
135
+
}
136
+