DomToArraySimplifier
class DomToArraySimplifier implements SimplifyToArrayInterface (View source)
Simplify a DOMDocument to an array.
Methods
No description
Convert structured data into a generic array, usable by generic array-based formatters. Objects that implement this interface may be attached to the FormatterManager, and will be used on any data structure that needs to be simplified into an array. An array simplifier should take no action other than to return its input data if it cannot simplify the provided data into an array.
Get all of the children of the provided element, with simplification.
Get the data from the children of the provided node in preliminary form.
Determine whether the children of the provided element are uniform.
Convert the children of the provided DOM element into an array.
Determine whether the provided value has additional unnecessary nesting. {"color": "red"} is converted to "red". No other simplification is done.
If the object has an 'id' or 'name' element, then use that as the array key when storing this value in its parent.
Convert the children of the provided DOM element into an array.
Details
__construct()
No description
canSimplify(ReflectionClass $dataType)
No description
array
simplifyToArray($structuredData, FormatterOptions $options)
Convert structured data into a generic array, usable by generic array-based formatters. Objects that implement this interface may be attached to the FormatterManager, and will be used on any data structure that needs to be simplified into an array. An array simplifier should take no action other than to return its input data if it cannot simplify the provided data into an array.
protected array
elementToArray(DOMNode $element)
Recursively convert the provided DOM element into a php array.
protected array
getNodeAttributes(DOMNode $element)
Get all of the attributes of the provided element.
protected array
getNodeChildren(DOMNode $element)
Get all of the children of the provided element, with simplification.
protected array
getNodeChildrenData(DOMNode $element)
Get the data from the children of the provided node in preliminary form.
protected bool
hasUniformChildren(DOMNode $element)
Determine whether the children of the provided element are uniform.
protected array
getUniformChildren(string $parentKey, DOMNode $element)
Convert the children of the provided DOM element into an array.
Here, 'uniform' means that all of the element names of the children are identical, and further, the element name of the parent is the plural form of the child names. When the children are uniform in this way, then the parent element name will be used as the key to store the children in, and the child list will be returned as a simple list with their (duplicate) element names omitted.
protected bool
valueCanBeSimplified(DOMNode $value)
Determine whether the provided value has additional unnecessary nesting. {"color": "red"} is converted to "red". No other simplification is done.
protected string
getIdOfValue(mixed $value)
If the object has an 'id' or 'name' element, then use that as the array key when storing this value in its parent.
protected array
getUniqueChildren(string $parentKey, DOMNode $element)
Convert the children of the provided DOM element into an array.
Here, 'unique' means that all of the element names of the children are different. Since the element names will become the key of the associative array that is returned, so duplicates are not supported. If there are any duplicates, then an exception will be thrown.