Bitrix-D7  20.0.0
scalarfield.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2012 Bitrix
7  */
8 
9 namespace Bitrix\Main\ORM\Fields;
12 
13 /**
14  * Scalar entity field class for non-array and non-object data types
15  * @package bitrix
16  * @subpackage main
17  */
18 abstract class ScalarField extends Field implements IStorable, ITypeHintable
19 {
20  protected $is_primary;
21 
22  protected $is_unique;
23 
24  protected $is_required;
25 
26  protected $is_autocomplete;
27 
28  protected $column_name = '';
29 
30  /** @var null|callable|mixed */
31  protected $default_value;
32 
33  /**
34  * ScalarField constructor.
35  *
36  * @param $name
37  * @param array $parameters deprecated, use configure* and add* methods instead
38  *
39  * @throws \Bitrix\Main\SystemException
40  */
41  public function __construct($name, $parameters = array())
42  {
43  parent::__construct($name, $parameters);
44 
45  $this->is_primary = (isset($parameters['primary']) && $parameters['primary']);
46  $this->is_unique = (isset($parameters['unique']) && $parameters['unique']);
47  $this->is_required = (isset($parameters['required']) && $parameters['required']);
48  $this->is_autocomplete = (isset($parameters['autocomplete']) && $parameters['autocomplete']);
49 
50  $this->column_name = isset($parameters['column_name']) ? $parameters['column_name'] : $this->name;
51  $this->default_value = isset($parameters['default_value']) ? $parameters['default_value'] : null;
52  }
53 
54  /**
55  * @return int
56  */
57  public function getTypeMask()
58  {
59  return FieldTypeMask::SCALAR;
60  }
61 
62  /**
63  * @param boolean $value
64  *
65  * @return $this
66  */
67  public function configurePrimary($value = true)
68  {
69  $this->is_primary = (bool) $value;
70  return $this;
71  }
72 
73  public function isPrimary()
74  {
75  return $this->is_primary;
76  }
77 
78  /**
79  * @param boolean $value
80  *
81  * @return $this
82  */
83  public function configureRequired($value = true)
84  {
85  $this->is_required = (bool) $value;
86  return $this;
87  }
88 
89  public function isRequired()
90  {
91  return $this->is_required;
92  }
93 
94  /**
95  * @param boolean $value
96  *
97  * @return $this
98  */
99  public function configureUnique($value = true)
100  {
101  $this->is_unique = (bool) $value;
102  return $this;
103  }
104 
105  public function isUnique()
106  {
107  return $this->is_unique;
108  }
109 
110  /**
111  * @param boolean $value
112  *
113  * @return $this
114  */
115  public function configureAutocomplete($value = true)
116  {
117  $this->is_autocomplete = (bool) $value;
118  return $this;
119  }
120 
121  public function isAutocomplete()
122  {
123  return $this->is_autocomplete;
124  }
125 
126  /**
127  * @param string $value
128  *
129  * @return $this
130  */
131  public function configureColumnName($value)
132  {
133  $this->column_name = $value;
134  return $this;
135  }
136 
137  public function getColumnName()
138  {
139  return $this->column_name;
140  }
141 
142  /**
143  * @param string $column_name
144  */
145  public function setColumnName($column_name)
146  {
147  $this->column_name = $column_name;
148  }
149 
150  /**
151  * @param callable|mixed $value
152  *
153  * @return $this
154  */
155  public function configureDefaultValue($value)
156  {
157  $this->default_value = $value;
158  return $this;
159  }
160 
161  /**
162  * @param array $row ORM data row in case of dependency value on other values
163  *
164  * @return callable|mixed|null
165  */
166  public function getDefaultValue($row = null)
167  {
168  if (!is_string($this->default_value) && is_callable($this->default_value))
169  {
170  return call_user_func($this->default_value, $row);
171  }
172  else
173  {
174  return $this->default_value;
175  }
176  }
177 
178  public function isValueEmpty($value)
179  {
180  if ($value instanceof SqlExpression)
181  {
182  $value = $value->compile();
183  }
184 
185  return (strval($value) === '');
186  }
187 
188  /**
189  * @return string
190  */
191  public function getGetterTypeHint()
192  {
193  return '\\string';
194  }
195 
196  /**
197  * @return string
198  */
199  public function getSetterTypeHint()
200  {
201  return '\\string';
202  }
203 }
Bitrix\Main\ORM\Fields\Field\$name
$name
Definition: main/lib/orm/fields/field.php:27
Bitrix\Main\ORM\Fields\ScalarField\getTypeMask
getTypeMask()
Definition: scalarfield.php:57
Bitrix\Main\ORM\Fields
Definition: arrayfield.php:9
Bitrix\Main\ORM\Fields\ScalarField\setColumnName
setColumnName($column_name)
Definition: scalarfield.php:145
Bitrix\Main\ORM\Fields\ScalarField\$default_value
$default_value
Definition: scalarfield.php:31
Bitrix\Main\ORM\Fields\ScalarField\$is_autocomplete
$is_autocomplete
Definition: scalarfield.php:26
Bitrix\Main\ORM\Fields\ScalarField\isAutocomplete
isAutocomplete()
Definition: scalarfield.php:121
Bitrix\Main\ORM\Fields\ScalarField\__construct
__construct($name, $parameters=array())
ScalarField constructor.
Definition: scalarfield.php:41
Bitrix\Main\ORM\Fields\ScalarField\getDefaultValue
getDefaultValue($row=null)
Definition: scalarfield.php:166
Bitrix\Main\ORM\Fields\ScalarField\getSetterTypeHint
getSetterTypeHint()
Definition: scalarfield.php:199
Bitrix\Main\ORM\Fields\ScalarField
Definition: scalarfield.php:18
Bitrix\Main\DB\SqlExpression
Definition: sqlexpression.php:18
Bitrix\Main\ORM\Fields\ScalarField\configureAutocomplete
configureAutocomplete($value=true)
Definition: scalarfield.php:115
Bitrix\Main\ORM\Fields\ScalarField\configureRequired
configureRequired($value=true)
Definition: scalarfield.php:83
Bitrix\Main\ORM\Fields\IStorable
Definition: istorable.php:15
Bitrix\Main\ORM\Fields\ScalarField\getColumnName
getColumnName()
Definition: scalarfield.php:137
Bitrix\Sender\Connector\__construct
__construct(Base $connector)
Constructor.
Definition: resultview.php:40
Bitrix\Main\ORM\Fields\Field
Definition: main/lib/orm/fields/field.php:24
Bitrix\Main\ORM\Fields\FieldTypeMask
Definition: fieldtypemask.php:15
Bitrix\Main\ORM\Fields\ITypeHintable
Definition: itypehintable.php:13
Bitrix\Main\ORM\Fields\FieldTypeMask\SCALAR
const SCALAR
Definition: fieldtypemask.php:17
Bitrix\Main\ORM\Fields\ScalarField\isRequired
isRequired()
Definition: scalarfield.php:89
Bitrix\Main\ORM\Fields\ScalarField\configureUnique
configureUnique($value=true)
Definition: scalarfield.php:99
Bitrix\Main\ORM\Fields\ScalarField\configureDefaultValue
configureDefaultValue($value)
Definition: scalarfield.php:155
Bitrix\Main\ORM\Fields\ScalarField\isPrimary
isPrimary()
Definition: scalarfield.php:73
Bitrix\Main\ORM\Fields\ScalarField\isValueEmpty
isValueEmpty($value)
Definition: scalarfield.php:178
Bitrix\Main\ORM\Fields\ScalarField\configureColumnName
configureColumnName($value)
Definition: scalarfield.php:131
Bitrix\Main\ORM\Fields\ScalarField\$is_unique
$is_unique
Definition: scalarfield.php:22
Bitrix\Main\ORM\Fields\ScalarField\configurePrimary
configurePrimary($value=true)
Definition: scalarfield.php:67
Bitrix\Main\ORM\Fields\ScalarField\isUnique
isUnique()
Definition: scalarfield.php:105
Bitrix\Main\ORM\Fields\ScalarField\getGetterTypeHint
getGetterTypeHint()
Definition: scalarfield.php:191
Bitrix\Main\ORM\Fields\ScalarField\$column_name
$column_name
Definition: scalarfield.php:28
Bitrix\Main\ORM\Fields\ScalarField\$is_primary
$is_primary
Definition: scalarfield.php:20
Bitrix\Main\ORM\Fields\ScalarField\$is_required
$is_required
Definition: scalarfield.php:24