final class PositionalArraySorter (View source)

Flexible array sorter that sorts an array according to a "position" metadata.

The expected format for the $subject is:

array( array( 'foo' => 'bar' 'position' => '', ), array( 'foo' => 'baz' 'position' => '', ), )

The supports one of the following syntax: start () end () before () after ()

where "weight" is the priority that defines which of two conflicting positions overrules the other, "key" is a string that references another key in the $subject and "numerical-order" is an integer that defines the order independently of the other keys. With the $positionPropertyPath parameter the property path to the position string can be changed.

Methods

__construct(array $subject, string $positionPropertyPath = 'position', bool $removeNullValues = true)

No description

array
toArray()

Returns a sorted copy of the subject array

array
getSortedKeys()

Returns the keys of $this->subject sorted according to the position meta data

Details

__construct(array $subject, string $positionPropertyPath = 'position', bool $removeNullValues = true)

No description

Parameters

array $subject

The source array to sort

string $positionPropertyPath

optional property path to the string that contains the position

bool $removeNullValues

if set to TRUE (default), null-values of the subject are removed

array toArray()

Returns a sorted copy of the subject array

Return Value

array

Exceptions

InvalidPositionException

array getSortedKeys()

Returns the keys of $this->subject sorted according to the position meta data

TODO Detect circles in after / before dependencies (#52185)

Return Value

array

an ordered list of keys

Exceptions

InvalidPositionException