class DomToArraySimplifier implements SimplifyToArrayInterface (View source)

Simplify a DOMDocument to an array.

Methods

__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.

array
elementToArray(DOMNode $element)

Recursively convert the provided DOM element into a php array.

array
getNodeAttributes(DOMNode $element)

Get all of the attributes of the provided element.

array
getNodeChildren(DOMNode $element)

Get all of the children of the provided element, with simplification.

array
getNodeChildrenData(DOMNode $element)

Get the data from the children of the provided node in preliminary form.

bool
hasUniformChildren(DOMNode $element)

Determine whether the children of the provided element are uniform.

array
getUniformChildren(string $parentKey, DOMNode $element)

Convert the children of the provided DOM element into an array.

bool
valueCanBeSimplified(DOMNode $value)

Determine whether the provided value has additional unnecessary nesting. {"color": "red"} is converted to "red". No other simplification is done.

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.

array
getUniqueChildren(string $parentKey, DOMNode $element)

Convert the children of the provided DOM element into an array.

Details

__construct()

No description

canSimplify(ReflectionClass $dataType)

No description

Parameters

ReflectionClass $dataType

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.

Parameters

$structuredData
FormatterOptions $options

Return Value

array

protected array elementToArray(DOMNode $element)

Recursively convert the provided DOM element into a php array.

Parameters

DOMNode $element

Return Value

array

protected array getNodeAttributes(DOMNode $element)

Get all of the attributes of the provided element.

Parameters

DOMNode $element

Return Value

array

protected array getNodeChildren(DOMNode $element)

Get all of the children of the provided element, with simplification.

Parameters

DOMNode $element

Return Value

array

protected array getNodeChildrenData(DOMNode $element)

Get the data from the children of the provided node in preliminary form.

Parameters

DOMNode $element

Return Value

array

protected bool hasUniformChildren(DOMNode $element)

Determine whether the children of the provided element are uniform.

Parameters

DOMNode $element

Return Value

bool

See also

getUniformChildren()
below.

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.

Parameters

string $parentKey
DOMNode $element

Return Value

array

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.

Parameters

DOMNode $value

Return Value

bool

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.

Parameters

mixed $value

Return Value

string

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.

Parameters

string $parentKey
DOMNode $element

Return Value

array