Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
stringfield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
11
use
Bitrix\Main\DB\SqlExpression
;
12
19
class
StringField
extends
ScalarField
20
{
25
protected
$format
=
null
;
26
28
protected
$size
=
null
;
29
38
function
__construct
(
$name
, $parameters = array())
39
{
40
parent::__construct(
$name
, $parameters);
41
42
if
(!empty($parameters[
'format'
]))
43
{
44
$this->format = $parameters[
'format'
];
45
}
46
if
(isset($parameters[
'size'
]) && intval($parameters[
'size'
]) > 0)
47
{
48
$this->size = intval($parameters[
'size'
]);
49
}
50
}
51
57
public
function
configureFormat
(
$format
)
58
{
59
$this->format =
$format
;
60
return
$this;
61
}
62
67
public
function
getFormat
()
68
{
69
return
$this->format
;
70
}
71
77
public
function
getValidators
()
78
{
79
$validators
= parent::getValidators();
80
81
if
($this->format !==
null
)
82
{
83
$validators
[] =
new
Validators\RegExpValidator
($this->format);
84
}
85
86
return
$validators
;
87
}
88
94
public
function
configureSize
(
$size
)
95
{
96
$this->size =
$size
;
97
return
$this;
98
}
99
104
public
function
getSize
()
105
{
106
return
$this->size
;
107
}
108
114
public
function
cast
($value)
115
{
116
if
($this->is_nullable && $value ===
null
)
117
{
118
return
$value;
119
}
120
121
if
($value instanceof
SqlExpression
)
122
{
123
return
$value;
124
}
125
126
$value = (string) $value;
127
128
if
($this->size !==
null
)
129
{
130
$value = mb_substr($value, 0, $this->size);
131
}
132
133
return
$value;
134
}
135
142
public
function
convertValueFromDb
($value)
143
{
144
return
$this->
getConnection
()->getSqlHelper()->convertFromDbString($value);
145
}
146
153
public
function
convertValueToDb
($value)
154
{
155
if
($value instanceof
SqlExpression
)
156
{
157
return
$value;
158
}
159
160
return
$value ===
null
&& $this->is_nullable
161
? $value
162
: $this->
getConnection
()->getSqlHelper()->convertToDbString($value);
163
}
164
}
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Main\ORM\Fields\Field\$name
$name
Definition
field.php:27
Bitrix\Main\ORM\Fields\Field\$validators
$validators
Definition
field.php:42
Bitrix\Main\ORM\Fields\Field\getConnection
getConnection()
Definition
field.php:626
Bitrix\Main\ORM\Fields\ScalarField
Definition
scalarfield.php:19
Bitrix\Main\ORM\Fields\StringField
Definition
stringfield.php:20
Bitrix\Main\ORM\Fields\StringField\configureSize
configureSize($size)
Definition
stringfield.php:94
Bitrix\Main\ORM\Fields\StringField\$format
$format
Definition
stringfield.php:25
Bitrix\Main\ORM\Fields\StringField\configureFormat
configureFormat($format)
Definition
stringfield.php:57
Bitrix\Main\ORM\Fields\StringField\getValidators
getValidators()
Definition
stringfield.php:77
Bitrix\Main\ORM\Fields\StringField\cast
cast($value)
Definition
stringfield.php:114
Bitrix\Main\ORM\Fields\StringField\getSize
getSize()
Definition
stringfield.php:104
Bitrix\Main\ORM\Fields\StringField\__construct
__construct($name, $parameters=array())
Definition
stringfield.php:38
Bitrix\Main\ORM\Fields\StringField\convertValueFromDb
convertValueFromDb($value)
Definition
stringfield.php:142
Bitrix\Main\ORM\Fields\StringField\getFormat
getFormat()
Definition
stringfield.php:67
Bitrix\Main\ORM\Fields\StringField\$size
$size
Definition
stringfield.php:28
Bitrix\Main\ORM\Fields\StringField\convertValueToDb
convertValueToDb($value)
Definition
stringfield.php:153
Bitrix\Main\ORM\Fields\Validators\RegExpValidator
Definition
regexpvalidator.php:18
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
modules
main
lib
orm
fields
stringfield.php
Создано системой
1.10.0