class Map implements ArrayAccess, Countable, IteratorAggregate (View source)

deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Map

Creates a map from an SS_List by defining a key column and a value column.

Properties

protected $list
protected $keyField
protected $valueField
protected array $firstItems
protected array $lastItems

Methods

public
__construct(SS_List $list, string $keyField = "ID", string $valueField = "Title")

Construct a new map around an SS_list.

public
setKeyField($keyField)

Set the key field for this map.

public
setValueField($valueField)

Set the value field for this map.

public
array
toArray()

Return an array equivalent to this map.

public
array
keys()

Return all the keys of this map.

public
array
values()

Return all the values of this map.

public
$this
unshift($key, $value)

Unshift an item onto the start of the map.

public
$this
push($key, $value)

Pushes an item onto the end of the map.

public
bool
offsetExists(mixed $key)

No description

public
mixed
offsetGet(mixed $key)

No description

public
void
offsetSet(mixed $key, mixed $value)

Sets a value in the map by a given key that has been set via Map::push()} or {@link Map::unshift()

public
void
offsetUnset(mixed $key)

Removes a value in the map by a given key which has been added to the map via Map::push()} or {@link Map::unshift()

public
getIterator()

Returns an Map_Iterator instance for iterating over the complete set of items in the map.

protected
mixed
extractValue(array|object $item, string $key)

Extracts a value from an item in the list, where the item is either an object or array.

public
int
count()

Returns the count of items in the list including the additional items set through Map::push()} and {@link Map::unshift.

Details

__construct(SS_List $list, string $keyField = "ID", string $valueField = "Title")

Construct a new map around an SS_list.

Parameters

SS_List $list

The list to build a map from

string $keyField

The field to use as the key of each map entry

string $valueField

The field to use as the value of each map entry

setKeyField($keyField)

Set the key field for this map.

Parameters

$keyField

setValueField($valueField)

Set the value field for this map.

Parameters

$valueField

array toArray()

Return an array equivalent to this map.

Return Value

array

array keys()

Return all the keys of this map.

Return Value

array

array values()

Return all the values of this map.

Return Value

array

$this unshift($key, $value)

Unshift an item onto the start of the map.

Stores the value in addition to the DataQuery for the map.

Parameters

$key
$value

Return Value

$this

$this push($key, $value)

Pushes an item onto the end of the map.

Parameters

$key
$value

Return Value

$this

bool offsetExists(mixed $key)

No description

Parameters

mixed $key

Return Value

bool

mixed offsetGet(mixed $key)

No description

Parameters

mixed $key

Return Value

mixed

void offsetSet(mixed $key, mixed $value)

Sets a value in the map by a given key that has been set via Map::push()} or {@link Map::unshift()

Keys in the map cannot be set since these values are derived from a DataQuery} instance. In this case, use {@link Map::toArray() and manipulate the resulting array.

Parameters

mixed $key
mixed $value

Return Value

void

Exceptions

BadMethodCallException

void offsetUnset(mixed $key)

Removes a value in the map by a given key which has been added to the map via Map::push()} or {@link Map::unshift()

Keys in the map cannot be unset since these values are derived from a DataQuery} instance. In this case, use {@link Map::toArray() and manipulate the resulting array.

Parameters

mixed $key

Return Value

void

Exceptions

BadMethodCallException

Traversable getIterator()

Returns an Map_Iterator instance for iterating over the complete set of items in the map.

Return Value

Traversable

protected mixed extractValue(array|object $item, string $key)

Extracts a value from an item in the list, where the item is either an object or array.

Parameters

array|object $item
string $key

Return Value

mixed

int count()

Returns the count of items in the list including the additional items set through Map::push()} and {@link Map::unshift.

Return Value

int