public function encode(mixed
$data, string
$format, array
$context =
[]): string
{ $encoderIgnoredNodeTypes =
$context[self::ENCODER_IGNORED_NODE_TYPES
] ??
$this->defaultContext
[self::ENCODER_IGNORED_NODE_TYPES
];
$ignorePiNode = \
in_array(\XML_PI_NODE,
$encoderIgnoredNodeTypes, true
);
if ($data instanceof \DOMDocument
) { return $data->
saveXML($ignorePiNode ?
$data->documentElement : null
);
} $xmlRootNodeName =
$context[self::ROOT_NODE_NAME
] ??
$this->defaultContext
[self::ROOT_NODE_NAME
];
$dom =
$this->
createDomDocument($context);
if (null !==
$data && !\
is_scalar($data)) { $root =
$dom->
createElement($xmlRootNodeName);
$dom->
appendChild($root);
$this->
buildXml($root,
$data,
$format,
$context,
$xmlRootNodeName);
} else { $this->
appendNode($dom,
$data,
$format,
$context,
$xmlRootNodeName);
} return $dom->
saveXML($ignorePiNode ?
$dom->documentElement : null,
$context[self::SAVE_OPTIONS
] ??
$this->defaultContext
[self::SAVE_OPTIONS
]);
}