The normalize()
method converts the node into a structured associative array, representing all its properties and child nodes in a format suitable for further processing or serialization.
Description
public NodeJsonEncoder::normalize(): array
Parameters
None.
Return Value
Returns an associative array representation of the node, including its properties. Each child node is recursively normalized into the same structure.
Exceptions
None
Example
use Ucscode\UssElement\Node\ElementNode;
use Ucscode\UssElement\Serializer\NodeJsonEncoder;
$node = new ElementNode('div', ['class' => 'container']);
$node->setInnerHtml('Hello World');
$encoder = new NodeJsonEncoder($node);
$array = $encoder->normalize();
Result Output
[
'nodeId' => 1,
'nodeType' => 1,
'nodeName' => 'DIV',
'parentId' => null,
'attributes' => [
'class' => 'container',
],
'void' => false,
'visible' => true,
'meta' => [],
'childNodes' => [
[
'nodeId' => 2,
'nodeType' => 3,
'nodeName' => '#TEXT',
'parentId' => 1,
'attributes' => [],
'void' => false,
'visible' => true,
'meta' => [
'data' => 'Hello World',
],
'childNodes' => [],
],
],
];