Class \Prado\Collections\TPriorityMap
TPriorityMap implements a collection that takes key-value pairs with a priority to allow key-value pairs to be ordered. This ordering is important when flattening the map. When flattening the map, if some key-value pairs are required to be before or after others, use this class to keep order to your map.
You can access, add or remove an item with a key by using itemAt, add, and remove. These functions can optionally take a priority parameter to allow access to specific priorities. TPriorityMap is functionally backward compatible with TMap.
To get the number of the items in the map, use getCount. TPriorityMap can also be used like a regular array as follows,
$map[$key]=$value; // add a key-value pair
unset($map[$key]); // remove the value with the specified key
if(isset($map[$key])) // if the map contains the key
foreach($map as $key=>$value) // traverse the items in the map
$n=count($map); // returns the number of items in the map
Using standard array access method like these will always use the default priority.
An item that doesn't specify a priority will receive the default priority. The default priority is set during the instantiation of a new TPriorityMap. If no custom default priority is specified, the standard default priority of 10 is used.
Priorities with significant digits below precision will be rounded.
A priority may also be a numeric with decimals. This is set during the instantiation of a new TPriorityMap. The default is 8 decimal places for a priority. If a negative number is used, rounding occurs into the integer space rather than in the decimal space. See round.
Class hierarchy
- \Prado\Collections\TPriorityMap implements IPriorityCollection uses TPriorityCollectionTrait
- \Prado\Collections\TMap implements IteratorAggregate, ArrayAccess, Countable
- \Prado\TComponent
Since: 3.2a
public
|
__construct([null|array<string|int, mixed>|TPriorityList|TPriorityMap|Traversable $data = null ][, bool|null $readOnly = null ][, numeric-string|int|float|null $defaultPriority = null ][, int|null $precision = null ]) : mixed
Constructor.
Initializes the array with an array or an iterable object. |
public
|
add(mixed $key, mixed $value[, null|(numeric) $priority = null ]) : mixed
Adds an item into the map. A third parameter may be used to set the priority
of the item within the map. Priority is primarily used during when flattening
the map into an array where order may be and important factor of the key-value
pairs within the array.
Note, if the specified key already exists, the old value will be overwritten. No duplicate keys are allowed regardless of priority. |
public
|
|
public
|
|
public
|
copyFrom(array<string|int, mixed>|TPriorityList|TPriorityMap|Traversable $data) : void
Copies iterable data into the map.
Note, existing data in the map will be cleared first. |
public
|
|
public
|
getKeys() : array<string|int, mixed>
Returns the keys within the map ordered through the priority of each key-value pair
|
public
|
|
public
|
itemAt(mixed $key[, null|false|(numeric) $priority = false ]) : mixed
Returns the item with the specified key. If a priority is specified, only items
within that specific priority will be selected.
|
public
|
|
public
|
mergeWith(array<string|int, mixed>|TPriorityList|TPriorityMap|Traversable $data) : void
Merges iterable data into the map.
Existing data in the map will be kept and overwritten if the keys are the same. |
public
|
priorityAt(mixed $key) : false|(numeric)
Returns the priority of an item at a particular key. This searches the map for the item.
|
public
|
priorityOf(mixed $item) : false|(numeric)
Returns the priority of a particular item within the map. This searches the map for the item.
|
public
|
remove(mixed $key[, null|false|(numeric) $priority = false ]) : mixed
Removes an item from the map by its key. If no priority, or false, is specified
then priority is irrelevant. If null is used as a parameter for priority, then
the priority will be the default priority. If a priority is specified, or
the default priority is specified, only key-value pairs in that priority
will be affected.
|
public
|
setPriorityAt(mixed $key[, null|(numeric) $priority = null ]) : numeric-string|int|float
This changes an item's priority. Specify the item and the new priority.
This method is exactly the same as offsetGet. |
protected
|
_getZappableSleepProps(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. |
private
|
getPriorityCombineStyle() : bool
This is required for TPriorityCollectionTrait to determine the style of combining
arrays.
|
\Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |