PositionalArraySorter
class PositionalArraySorter (View source)
Flexible array sorter that sorts an array according to a "position" meta data.
The expected format for the $subject is:
array(
array(
'foo' => 'bar'
'position' => '
The
Properties
protected array | $subject | ||
protected string | $positionPropertyPath | ||
protected array | $startKeys | ||
protected array | $middleKeys | ||
protected array | $endKeys | ||
protected array | $beforeKeys | ||
protected array | $afterKeys |
Methods
No description
Returns a sorted copy of the subject array
Returns the keys of $this->subject sorted according to the position meta data
Extracts all "middle" keys from $arrayKeysWithPosition. Those are all keys with a numeric position.
Extracts all "start" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "start" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
Extracts all "end" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "end" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
Extracts all "before" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "before" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
Extracts all "after" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "after" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
Collect the array keys inside $this->subject with each position meta-argument.
Flattens start-, middle-, end-, before- and afterKeys to a single dimension and merges them together to a single array
Details
__construct(array $subject, string $positionPropertyPath = 'position')
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
TODO Detect circles in after / before dependencies (#52185)
protected void
extractMiddleKeys(array $arrayKeysWithPosition)
Extracts all "middle" keys from $arrayKeysWithPosition. Those are all keys with a numeric position.
The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
protected void
extractStartKeys(array $arrayKeysWithPosition)
Extracts all "start" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "start" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
protected void
extractEndKeys(array $arrayKeysWithPosition)
Extracts all "end" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "end" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
protected void
extractBeforeKeys(array $arrayKeysWithPosition)
Extracts all "before" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "before" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
protected void
extractAfterKeys(array $arrayKeysWithPosition)
Extracts all "after" keys from $arrayKeysWithPosition. Those are all keys with a position starting with "after" The result is a multi-dimensional arrays where the KEY of each array is a PRIORITY and the VALUE is an array of matching KEYS This also removes matching keys from the given $arrayKeysWithPosition
protected array
collectArrayKeysAndPositions()
Collect the array keys inside $this->subject with each position meta-argument.
If there is no position but the array is numerically ordered, we use the array index as position.
protected array
generateSortedKeysMap()
Flattens start-, middle-, end-, before- and afterKeys to a single dimension and merges them together to a single array