Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
arrayfield.php
1<?php
10
13
19{
22
24 protected $encodeFunction;
25
27 protected $decodeFunction;
28
29 public function __construct($name, $parameters = [])
30 {
32
33 $this->addSaveDataModifier([$this, 'encode']);
34 $this->addFetchDataModifier([$this, 'decode']);
35
36 parent::__construct($name, $parameters);
37 }
38
45 {
46 $this->serializationType = 'json';
47 $this->encodeFunction = [$this, 'encodeJson'];
48 $this->decodeFunction = [$this, 'decodeJson'];
49
50 return $this;
51 }
52
58 public function configureSerializationPhp()
59 {
60 $this->serializationType = 'php';
61 $this->encodeFunction = [$this, 'encodePhp'];
62 $this->decodeFunction = [$this, 'decodePhp'];
63
64 return $this;
65 }
66
74 public function configureSerializeCallback($callback)
75 {
76 $this->encodeFunction = $callback;
77 $this->serializationType = 'custom';
78
79 return $this;
80 }
81
89 public function configureUnserializeCallback($callback)
90 {
91 $this->decodeFunction = $callback;
92 $this->serializationType = 'custom';
93
94 return $this;
95 }
96
102 public function encode($value)
103 {
104 $callback = $this->encodeFunction;
105 return $callback($value);
106 }
107
113 public function decode($value)
114 {
115 if($value <> '')
116 {
117 $callback = $this->decodeFunction;
118 return $callback($value);
119 }
120
121 return [];
122 }
123
130 public function encodeJson($value)
131 {
132 return Json::encode($value);
133 }
134
141 public function decodeJson($value)
142 {
143 return Json::decode($value);
144 }
145
151 public function encodePhp($value)
152 {
153 return serialize($value);
154 }
155
161 public function decodePhp($value)
162 {
163 return unserialize($value);
164 }
165
171 public function cast($value)
172 {
173 if ($this->is_nullable && $value === null)
174 {
175 return $value;
176 }
177
178 if ($value instanceof SqlExpression)
179 {
180 return $value;
181 }
182
183 return (array) $value;
184 }
185
192 public function convertValueFromDb($value)
193 {
194 return $this->getConnection()->getSqlHelper()->convertFromDbString($value);
195 }
196
203 public function convertValueToDb($value)
204 {
205 if ($value instanceof SqlExpression)
206 {
207 return $value;
208 }
209
210 return $value === null && $this->is_nullable
211 ? $value
212 : $this->getConnection()->getSqlHelper()->convertToDbString($value);
213 }
214
218 public function getGetterTypeHint()
219 {
220 return $this->getNullableTypeHint('array');
221 }
222
226 public function getSetterTypeHint()
227 {
228 return $this->getNullableTypeHint('array');
229 }
230}
__construct($name, $parameters=[])
addFetchDataModifier($modifier)
Definition field.php:344
addSaveDataModifier($modifier)
Definition field.php:420