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