/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Convert/Xml.php
42 строки
1 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ namespace Magento\Framework\Convert; /** * Convert xml data (SimpleXMLElement object) to array */ class Xml { /** * Transform \SimpleXMLElement to associative array * \SimpleXMLElement must be conform structure, generated by assocToXml() * * @param \SimpleXMLElement $xml * @return array */ public function xmlToAssoc(\SimpleXMLElement $xml) { $array = []; foreach ($xml as $key => $value) { if (isset($value->{$key})) { $i = 0; foreach ($value->{$key} as $v) { $array[$key][$i++] = (string)$v; } } else { // try to transform it into string value, trimming spaces between elements $array[$key] = trim((string)$value); if (empty($array[$key]) && !empty($value)) { $array[$key] = $this->xmlToAssoc($value); } else { // untrim strings values $array[$key] = (string)$value; } } } return $array; } }