Trait \Prado\Collections\TPriorityCollectionTrait
This trait implements the common properties and methods of Priority Collection classes.
The trait adds a boolean for whether or not _d is ordered, a cached flattened array _fd, a default priority (by default, 10) _dp, and precision of priorities (by default, 8 [decimal places]) _p.
The trait adds methods:
- getDefaultPriority returns the default priority of items without priority.
- setDefaultPriority sets the default priority. (protected)
- getPrecision returns the precision of priorities.
- setPrecision sets the precision of priorities. (protected)
- ensurePriority standardize and round priorities. (protected)
- sortPriorities sorts _d and flags as sorted. (protected)
- flattenPriorities flattens the priority items, in order into cache.. (protected)
- getPriorities gets the priorities of the collection.
- getPriorityCount gets the number of items at a priority.
- itemsAtPriority gets the items at a given priority.
- getIterator overrides subclasses for an iterator of the flattened array.
- ToArray the flattened collection in order.
- ToPriorityArray the array of priorities (keys) and array of items (value).
- ToArrayBelowPriority the items below a Priority, default is not inclusive
- ToArrayAbovePriority the items above a priority, default is inclusive.
- _priorityZappableSleepProps to add the excluded trait properties on sleep.
The priorities are implemented as numeric strings.
Any class using this trait must implement a getPriorityCombineStyle method to determine if arrays are merged or replaced to combine together.
For example, something like this is required in your class:
private function getPriorityCombineStyle(): bool
{
return true; // for merge (list style), and false for replace (map style)
}
Trait hierarchy
Author: Brad Anderson <belisoful@icloud.com>Since: 4.3.0
public
|
|
public
|
getIterator() : Iterator
Returns an iterator for traversing the items in the list.
This method is required by the interface \IteratorAggregate. |
public
|
|
public
|
getPriorities() : array<string|int, mixed>
This returns a list of the priorities within this list, ordered lowest to highest.
|
public
|
getPriorityCount([null|(numeric) $priority = null ]) : int
Gets the number of items at a priority within the list
|
public
|
itemsAtPriority([null|(numeric) $priority = null ]) : array<string|int, mixed>|null
Gets all the items at a specific priority.
|
public
|
setDefaultPriority(numeric-string|int|float $value) : mixed
This must be called internally or when instantiated.
|
public
|
setPrecision(int $value) : void
This must be called internally or when instantiated.
This resets the array priorities to the new precision and adjusts the DefaultPriority to the new precision as well. |
public
|
|
public
|
toArrayAbovePriority(numeric-string|int|float $priority[, bool $inclusive = true ]) : array<string|int, mixed>
Combines the map elements which have a priority above the parameter value
|
public
|
toArrayBelowPriority(numeric-string|int|float $priority[, bool $inclusive = false ]) : array<string|int, mixed>
Combines the map elements which have a priority below the parameter value
|
public
|
|
protected
|
_priorityZappableSleepProps(array<string|int, mixed> &$exprops) : mixed
Returns an array with the names of all variables of this object that should NOT be serialized
because their value is the default one or useless to be cached for the next page loads.
Reimplement in derived classes to add new variables, but remember to also to call the parent implementation first. |
protected
|
ensurePriority(mixed $priority) : string
Taken an input Priority and ensures its value.
Sets the default $priority when none is set, then rounds to the proper precision and makes into a string. |
protected
|
flattenPriorities() : void
This flattens the priority list into a flat array [0,...,n-1] (with array_merge)
and a priority map into a single flat map of keys and values (with array_replace).
|
protected
|
|