Emergency fixes to fix a bunch of fatal errors

This commit is contained in:
Michael 2022-07-17 11:47:12 +00:00
parent 974564f75e
commit 2ddf37f32d
6 changed files with 27 additions and 23 deletions

View file

@ -42,9 +42,9 @@ class XML
* @param bool $remove_header Should the XML header be removed or not?
* @param array $namespaces List of namespaces
* @param bool $root interally used parameter. Mustn't be used from outside.
* @return void
* @return string
*/
public static function fromArray(array $array, &$xml, bool $remove_header = false, array $namespaces = [], bool $root = true)
public static function fromArray(array $array, &$xml, bool $remove_header = false, array $namespaces = [], bool $root = true): string
{
if ($root) {
foreach ($array as $key => $value) {
@ -130,6 +130,7 @@ class XML
self::fromArray($value, $element, $remove_header, $namespaces, false);
}
}
return '';
}
/**
@ -142,7 +143,7 @@ class XML
*/
public static function copy(&$source, &$target, string $elementname)
{
if (count($source->children()) == 0) {
if (is_string($source) && count($source->children()) == 0) {
$target->addChild($elementname, self::escape($source));
} else {
$child = $target->addChild($elementname);
@ -184,9 +185,9 @@ class XML
* @param array $attributes Array containing the attributes
* @return void
*/
public static function addElement(DOMDocument $doc, DOMElement &$parent, string $element, string $value = '', array $attributes = [])
public static function addElement(DOMDocument $doc, DOMElement &$parent, string $element, string $value = null, array $attributes = [])
{
$element = self::createElement($doc, $element, $value, $attributes);
$element = self::createElement($doc, $element, $value ?? '', $attributes);
$parent->appendChild($element);
}
@ -273,6 +274,7 @@ class XML
return [];
}
$parent = [];
libxml_use_internal_errors(true);
libxml_clear_errors();