Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
scalarfield.php
1<?php
12
18abstract class ScalarField extends Field implements IStorable, ITypeHintable
19{
20 protected $is_primary;
21
22 protected $is_unique;
23
24 protected $is_required;
25
27
29 protected $is_private;
30
32 protected $is_nullable;
33
34 protected $column_name = '';
35
37 protected $default_value;
38
47 public function __construct($name, $parameters = array())
48 {
49 parent::__construct($name, $parameters);
50
51 $this->is_primary = (isset($parameters['primary']) && $parameters['primary']);
52 $this->is_unique = (isset($parameters['unique']) && $parameters['unique']);
53 $this->is_required = (isset($parameters['required']) && $parameters['required']);
54 $this->is_autocomplete = (isset($parameters['autocomplete']) && $parameters['autocomplete']);
55 $this->is_private = (isset($parameters['private']) && $parameters['private']);
56 $this->is_nullable = (isset($parameters['nullable']) && $parameters['nullable']);
57
58 $this->column_name = $parameters['column_name'] ?? $this->name;
59 $this->default_value = $parameters['default_value'] ?? null;
60 }
61
65 public function getTypeMask()
66 {
68 }
69
75 public function configurePrimary($value = true)
76 {
77 $this->is_primary = (bool) $value;
78 return $this;
79 }
80
81 public function isPrimary()
82 {
83 return $this->is_primary;
84 }
85
91 public function configureRequired($value = true)
92 {
93 $this->is_required = (bool) $value;
94 return $this;
95 }
96
97 public function isRequired()
98 {
99 return $this->is_required;
100 }
101
107 public function configureUnique($value = true)
108 {
109 $this->is_unique = (bool) $value;
110 return $this;
111 }
112
113 public function isUnique()
114 {
115 return $this->is_unique;
116 }
117
123 public function configureAutocomplete($value = true)
124 {
125 $this->is_autocomplete = (bool) $value;
126 return $this;
127 }
128
129 public function isAutocomplete()
130 {
132 }
133
134
140 public function configurePrivate($value = true)
141 {
142 $this->is_private = (bool) $value;
143 return $this;
144 }
145
149 public function isPrivate()
150 {
151 return $this->is_private;
152 }
153
159 public function configureNullable($value = true)
160 {
161 $this->is_nullable = (bool) $value;
162 return $this;
163 }
164
168 public function isNullable()
169 {
170 return $this->is_nullable;
171 }
172
178 public function configureColumnName($value)
179 {
180 $this->column_name = $value;
181 return $this;
182 }
183
184 public function getColumnName()
185 {
186 return $this->column_name;
187 }
188
193 {
194 $this->column_name = $column_name;
195 }
196
202 public function configureDefaultValue($value)
203 {
204 $this->default_value = $value;
205 return $this;
206 }
207
213 public function getDefaultValue($row = null)
214 {
215 if (!is_string($this->default_value) && is_callable($this->default_value))
216 {
217 return call_user_func($this->default_value, $row);
218 }
219 else
220 {
222 }
223 }
224
225 public function isValueEmpty($value)
226 {
227 if ($value instanceof SqlExpression)
228 {
229 $value = $value->compile();
230 }
231
232 return ((string)$value === '');
233 }
234
238 public function getGetterTypeHint()
239 {
240 return $this->getNullableTypeHint('\\string');
241 }
242
246 public function getSetterTypeHint()
247 {
248 return $this->getNullableTypeHint('\\string');
249 }
250
255 protected function getNullableTypeHint(string $type): string
256 {
257 return $this->is_nullable ? '?' . $type : $type;
258 }
259}
__construct($name, $parameters=array())