32 $result = (
new EO_Source())
38 ->setConfig($this->buildConfigString($source->
getConfig()));
47 return Factory::makeSource($ormSource->getCode())
48 ->
setName($ormSource->getName())
49 ->setConfig($this->buildConfig($ormSource->getConfig()));
56 private function buildConfig(
string $configString): ?
Config
63 if (!CheckSerializedData($configString))
70 $configArray = unserialize($configString, [
'allowed_classes' =>
false]);
71 foreach ($configArray as $configArrayItem)
74 $this->convertArrayToConfigItem($configArrayItem)
85 private function buildConfigString(?
Config $config)
94 foreach ($config as $configItem)
96 $configArray[] = $this->convertConfigItemToArray($configItem);
99 return serialize($configArray);
106 private function convertConfigItemToArray(ConfigItem $configItem)
109 'code' => $configItem->getCode(),
110 'type' => $configItem->getType(),
111 'is_visible' => $configItem->isVisible(),
112 'sort' => $configItem->getSort(),
113 'value' => $configItem->getValue(),
121 private function convertArrayToConfigItem(array $array)
123 if (!isset($array[
'code']))
125 throw new RuntimeException(
'code is not specified');
128 $result =
new ConfigItem($array[
'code'], $array[
'type']);
130 if (isset($array[
'is_visible']))
132 $result->setIsVisible($array[
'is_visible']);
134 if (isset($array[
'sort']))
136 $result->setSort((
int)$array[
'sort']);
138 if (isset($array[
'value']))
140 $result->setValue(isset($array[
'value']) ? (
string)$array[
'value'] : null);