Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
enumfield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
11
use
Bitrix\Main\DB\SqlExpression
;
12
use
Bitrix\Main\SystemException
;
13
19
class
EnumField
extends
ScalarField
20
{
21
protected
$values
;
22
31
function
__construct
(
$name
, $parameters = array())
32
{
33
parent::__construct(
$name
, $parameters);
34
35
if
(isset($parameters[
'values'
]))
36
{
37
$this->values = $parameters[
'values'
];
38
}
39
}
40
41
public
function
postInitialize
()
42
{
43
if
(!is_array($this->values))
44
{
45
throw
new
SystemException
(sprintf(
46
'Parameter "values" for %s field in `%s` entity should be an array'
,
47
$this->name, $this->entity->getDataClass()
48
));
49
}
50
51
if
(empty($this->values))
52
{
53
throw
new
SystemException
(sprintf(
54
'Required parameter "values" for %s field in `%s` entity is not found'
,
55
$this->name, $this->entity->getDataClass()
56
));
57
}
58
}
59
65
public
function
configureValues
(
$values
)
66
{
67
$this->values =
$values
;
68
return
$this;
69
}
70
76
public
function
getValidators
()
77
{
78
$validators
= parent::getValidators();
79
80
if
($this->validation ===
null
)
81
{
82
$validators
[] =
new
Validators\EnumValidator
;
83
}
84
85
return
$validators
;
86
}
87
88
public
function
getValues
()
89
{
90
return
$this->values
;
91
}
92
98
public
function
cast
($value)
99
{
100
if
($this->is_nullable && $value ===
null
)
101
{
102
return
$value;
103
}
104
105
if
($value instanceof
SqlExpression
)
106
{
107
return
$value;
108
}
109
110
return
$value;
111
}
112
118
public
function
convertValueFromDb
($value)
119
{
120
return
$value;
121
}
122
129
public
function
convertValueToDb
($value)
130
{
131
if
($value instanceof
SqlExpression
)
132
{
133
return
$value;
134
}
135
136
return
$value ===
null
&& $this->is_nullable
137
? $value
138
: $this->
getConnection
()->getSqlHelper()->convertToDbString($value);
139
}
140
}
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Main\ORM\Fields\EnumField
Definition
enumfield.php:20
Bitrix\Main\ORM\Fields\EnumField\getValidators
getValidators()
Definition
enumfield.php:76
Bitrix\Main\ORM\Fields\EnumField\cast
cast($value)
Definition
enumfield.php:98
Bitrix\Main\ORM\Fields\EnumField\postInitialize
postInitialize()
Definition
enumfield.php:41
Bitrix\Main\ORM\Fields\EnumField\getValues
getValues()
Definition
enumfield.php:88
Bitrix\Main\ORM\Fields\EnumField\__construct
__construct($name, $parameters=array())
Definition
enumfield.php:31
Bitrix\Main\ORM\Fields\EnumField\convertValueFromDb
convertValueFromDb($value)
Definition
enumfield.php:118
Bitrix\Main\ORM\Fields\EnumField\configureValues
configureValues($values)
Definition
enumfield.php:65
Bitrix\Main\ORM\Fields\EnumField\convertValueToDb
convertValueToDb($value)
Definition
enumfield.php:129
Bitrix\Main\ORM\Fields\EnumField\$values
$values
Definition
enumfield.php:21
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\Validators\EnumValidator
Definition
enumvalidator.php:14
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
modules
main
lib
orm
fields
enumfield.php
Создано системой
1.10.0