Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configfactory.php
1<?php
2
4
13
14final class ConfigFactory
15{
26 public function createFromArray(array $params): ?Config
27 {
28 $name = (string)($params['NAME'] ?? '');
29 if (empty($name))
30 {
31 return null;
32 }
33
34 $type = $params['TYPE'] ?? null;
35
36 if (Types::RANGE === $type)
37 {
38 $config = new RangeConfig(
39 $name,
40 $params['min'] ?? null,
41 $params['max'] ?? null,
42 $params['step'] ?? null,
43 );
44 }
45 elseif (Types::MONEY === $type)
46 {
47 $currencyList = null;
48
49 if (isset($params['CURRENCY_LIST']) && is_array($params['CURRENCY_LIST']))
50 {
51 $currencyList = [];
52 foreach ($params['CURRENCY_LIST'] as $key => $value)
53 {
54 if (is_array($value))
55 {
56 if (isset($value['NAME'], $value['VALUE']))
57 {
58 $currencyList[$value['NAME']] = $value['VALUE'];
59 }
60 else
61 {
62 trigger_error('Invalid currency list format', E_USER_WARNING);
63 continue;
64 }
65 }
66 else
67 {
68 $currencyList[$key] = $value;
69 }
70 }
71 }
72
73 $config = new MoneyConfig($name, $currencyList);
74
75 if (isset($params['HTML_ENTITY']))
76 {
77 $config->setHtml($params['HTML_ENTITY'] === true);
78 }
79 }
80 elseif (Types::DROPDOWN === $type || Types::MULTISELECT === $type)
81 {
82 $items = [];
83
84 if (isset($params['items']) && is_array($params['items']))
85 {
86 $items = $params['items'];
87 }
88 elseif (isset($params['DATA']['ITEMS']))
89 {
90 foreach ($params['DATA']['ITEMS'] as $item)
91 {
92 $items[$item['VALUE']] = $item['NAME'];
93 }
94 }
95
96 $config = new ListConfig($name, $items, $type);
97 }
98 elseif (Types::CUSTOM === $type)
99 {
100 $config = new CustomConfig($name);
101
102 if (isset($params['HTML']))
103 {
104 $config->setHtml((string)$params['HTML']);
105 }
106 }
107 else
108 {
109 $config = new Config($name, $type);
110 }
111
112 if (isset($params['PLACEHOLDER']))
113 {
114 $config->setPlaceholder((string)$params['PLACEHOLDER']);
115 }
116
117 if (isset($params['DISABLED']))
118 {
119 $config->setDisabled(
120 is_bool($params['DISABLED']) ? $params['DISABLED'] : $params['DISABLED'] === 'Y'
121 );
122 }
123
124 return $config;
125 }
126
136 public function createFromColumn(Column $column): Config
137 {
138 return new Config(
139 $column->getId(),
140 Type::getEditorType($column->getType())
141 );
142 }
143}