Field.php
3.73 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
namespace NinjaForms\Includes\Handlers;
use NinjaForms\Includes\Contracts\Field as ContractsField;
/**
* Honor Field contract providing NF Field object methods
*
* Provides functionality normally handled by the field object created by
* \Ninja_Forms()->form()->get_field( $fieldId )
*
*
*/
class Field implements ContractsField
{
/**
* Field Id
*
* @var int
*/
protected $id = 0;
/**
* Field type
*
* @var string
*/
protected $type = '';
/**
* Field settings
*
* @var array
*/
protected $settings = [];
/**
* @inheritDoc
*/
public function get_id(): int
{
return $this->id;
}
/** @inheritDoc */
public function get_tmp_id()
{
return null;
}
/** @inheritDoc */
public function get_type(): string
{
return $this->type;
}
/** @inheritDoc */
public function get_setting($setting, $default = FALSE)
{
if (isset($this->settings[$setting])) {
$return = $this->settings[$setting];
} else {
$return = $default;
}
return $return;
}
/** @inheritDoc */
public function get_settings(): array
{
return $this->settings;
}
/** @inheritDoc */
public function update_setting($key, $value): Field
{
return $this;
}
/** @inheritDoc */
public function update_settings($data): Field
{
return $this;
}
/** @inheritDoc */
public function delete()
{
return $this;
}
/** @inheritDoc */
public function find($parent_id = '', array $where = array()): array
{
return [];
}
/** @inheritDoc */
public function get_object_settings($obj_array): array
{
return [];
}
/** @inheritDoc */
public function save()
{
}
/** @inheritDoc */
public function _insert_row($data = array()): void
{
}
/** @inheritDoc */
public function cache($cache = ''): Field
{
return $this;
}
/** @inheritDoc */
public function add_parent($parent_id, $parent_type): Field
{
return $this;
}
/** @inheritDoc */
public static function import(array $settings, $field_id = '', $is_conversion = FALSE): void
{
}
/**
* Construct entity from associative array
*
* @param array $items
* @return Field
*/
public static function fromArray(array $items): Field
{
$obj = new static();
foreach ($items as $property => $value) {
$obj = $obj->__set($property, $value);
}
return $obj;
}
/**
* Magic method getter for properties
*
* @param string $name
* @return void
*/
public function __get($name)
{
$getter = 'get' . ucfirst($name);
if (method_exists($this, $getter)) {
return call_user_func([$this, $getter]);
}
if (property_exists($this, $name)) {
return $this->$name;
}
if (isset($this->$name)) {
return $this->$name;
}
}
/**
* Magic method setter for properties
*
*
* @param string $name
* @param mixed $value
*/
public function __set(string $name, $value)
{
$setter = 'set' . ucfirst($name);
if (method_exists($this, $setter)) {
try {
return call_user_func([$this, $setter], $value);
} catch (\TypeError $e) {
// Do not set invalid type
return $this;
}
}
if (property_exists($this, $name)) {
$this->$name = $value;
return $this;
}
return $this;
}
}