Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
enumfield.php
1<?php
10
13
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 {
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}
__construct($name, $parameters=array())
Definition enumfield.php:31