Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
jsonfield.php
1<?php
3
5
9class JsonField extends PackedField
10{
11 public function tryUnpack()
12 {
13 $result = new Main\Result();
14 try
15 {
16 $value = Main\Web\Json::decode($this->packedValue);
17 if (!$value)
18 {
19 $result->addError(new Main\Error('Unavailable value for unpacking'));
20 }
21 }
22 catch (\Exception $e)
23 {
24 $result->addError(new Main\Error('Unavailable value for unpacking'));
25 }
26
27 return $result;
28 }
29
30 public function unpack()
31 {
32 try
33 {
34 $unpacked = Main\Web\Json::decode($this->packedValue);
35 if (!is_array($unpacked))
36 return null;
37
38 return $this->formatResult($unpacked);
39 }
40 catch (\Exception $e)
41 {
42 return null;
43 }
44 }
45
46 private function formatResult(array $fields)
47 {
48 foreach ($fields as &$field)
49 {
50 if (is_array($field))
51 {
52 $field = $this->formatResult($field);
53 }
54 elseif (CheckDateTime($field))
55 {
56 $field = new Main\Type\DateTime($field);
57 }
58 }
59
60 return $fields;
61 }
62}