Documentation

AbstractTypedMap extends AbstractMap
in package
implements TypedMapInterface Uses TypeTrait, ValueToStringTrait

This class provides a basic implementation of `TypedMapInterface`, to minimize the effort required to implement this interface.

Tags
template

K

template

T

extends

AbstractMap<T>

implements

TypedMapInterface<T>

Interfaces, Classes, Traits and Enums

TypedMapInterface
A `TypedMapInterface` represents a map of elements where key and value are typed.

Table of Contents

$data  : array<array-key, T>
The items of this array.
__construct()  : mixed
Constructs a new array object.
__serialize()  : array<array-key, T>
Returns data suitable for PHP serialization.
__unserialize()  : void
Adds unserialized data to the object.
clear()  : void
Removes all items from this array.
containsKey()  : bool
Returns `true` if this map contains a mapping for the specified key.
containsValue()  : bool
Returns `true` if this map maps one or more keys to the specified value.
count()  : int
Returns the number of items in this array.
get()  : T|null
Returns the value to which the specified key is mapped, `null` if this map contains no mapping for the key, or (optionally) `$defaultValue` if this map contains no mapping for the key.
getIterator()  : Traversable<array-key, T>
Returns an iterator for this array.
isEmpty()  : bool
Returns `true` if this array is empty.
keys()  : array<int, array-key>
Return an array of the keys contained in this map.
offsetExists()  : bool
Returns `true` if the given offset exists in this array.
offsetGet()  : T|null
Returns the value at the specified offset.
offsetSet()  : void
Sets the given value to the given offset in the array.
offsetUnset()  : void
Removes the given offset and its value from the array.
put()  : T|null
Associates the specified value with the specified key in this map.
putIfAbsent()  : T|null
Associates the specified value with the specified key in this map only if it is not already set.
remove()  : T|null
Removes the mapping for a key from this map if it is present.
removeIf()  : bool
Removes the entry for the specified key only if it is currently mapped to the specified value.
replace()  : T|null
Replaces the entry for the specified key only if it is currently mapped to some value.
replaceIf()  : bool
Replaces the entry for the specified key only if currently mapped to the specified value.
serialize()  : string
Returns a serialized string representation of this array object.
toArray()  : array<array-key, T>
Returns a native PHP array representation of this array object.
unserialize()  : void
Converts a serialized string representation into an instance object.
checkType()  : bool
Returns `true` if value is of the specified type.
toolValueToString()  : string
Returns a string representation of the value.

Properties

$data

The items of this array.

protected array<array-key, T> $data = []

Methods

__construct()

Constructs a new array object.

public __construct([array<array-key, T$data = [] ]) : mixed
Parameters
$data : array<array-key, T> = []

The initial items to add to this array.

Return values
mixed

__unserialize()

Adds unserialized data to the object.

public __unserialize(array<array-key, T$data) : void
Parameters
$data : array<array-key, T>
Return values
void

clear()

Removes all items from this array.

public clear() : void
Return values
void

containsKey()

Returns `true` if this map contains a mapping for the specified key.

public containsKey(mixed $key) : bool
Parameters
$key : mixed

The key to check in the map.

Tags
inheritDoc
Return values
bool

containsValue()

Returns `true` if this map maps one or more keys to the specified value.

public containsValue(mixed $value) : bool
Parameters
$value : mixed

The value to check in the map.

Tags
inheritDoc
Return values
bool

get()

Returns the value to which the specified key is mapped, `null` if this map contains no mapping for the key, or (optionally) `$defaultValue` if this map contains no mapping for the key.

public get(mixed $key[, mixed $defaultValue = null ]) : T|null
Parameters
$key : mixed

The key to return from the map.

$defaultValue : mixed = null

The default value to use if $key is not found.

Tags
inheritDoc
Return values
T|null

the value or null if the key could not be found.

isEmpty()

Returns `true` if this array is empty.

public isEmpty() : bool
Return values
bool

keys()

Return an array of the keys contained in this map.

public keys() : array<int, array-key>
Tags
inheritDoc
Return values
array<int, array-key>

offsetExists()

Returns `true` if the given offset exists in this array.

public offsetExists(string|int $offset) : bool
Parameters
$offset : string|int

The offset to check.

Tags
link

ArrayAccess::offsetExists()

Return values
bool

offsetGet()

Returns the value at the specified offset.

public offsetGet(string|int $offset) : T|null
Parameters
$offset : string|int

The offset for which a value should be returned.

Tags
link

ArrayAccess::offsetGet()

psalm-suppress

InvalidAttribute

Return values
T|null

the value stored at the offset, or null if the offset does not exist.

offsetSet()

Sets the given value to the given offset in the array.

public offsetSet(K|null $offset, T $value) : void
Parameters
$offset : K|null
$value : T
Tags
inheritDoc
psalm-suppress

MoreSpecificImplementedParamType

Return values
void

offsetUnset()

Removes the given offset and its value from the array.

public offsetUnset(string|int $offset) : void
Parameters
$offset : string|int

The offset to remove from the array.

Tags
link

ArrayAccess::offsetUnset()

Return values
void

put()

Associates the specified value with the specified key in this map.

public put(mixed $key, mixed $value) : T|null
Parameters
$key : mixed

The key to put or replace in the map.

$value : mixed

The value to store at $key.

Tags
inheritDoc
Return values
T|null

the previous value associated with key, or null if there was no mapping for $key.

putIfAbsent()

Associates the specified value with the specified key in this map only if it is not already set.

public putIfAbsent(mixed $key, mixed $value) : T|null
Parameters
$key : mixed

The key to put in the map.

$value : mixed

The value to store at $key.

Tags
inheritDoc
Return values
T|null

the previous value associated with key, or null if there was no mapping for $key.

remove()

Removes the mapping for a key from this map if it is present.

public remove(mixed $key) : T|null
Parameters
$key : mixed

The key to remove from the map.

Tags
inheritDoc
Return values
T|null

the previous value associated with key, or null if there was no mapping for $key.

removeIf()

Removes the entry for the specified key only if it is currently mapped to the specified value.

public removeIf(mixed $key, mixed $value) : bool
Parameters
$key : mixed

The key to remove from the map.

$value : mixed

The value to match.

Tags
inheritDoc
Return values
bool

true if the value was removed.

replace()

Replaces the entry for the specified key only if it is currently mapped to some value.

public replace(mixed $key, mixed $value) : T|null
Parameters
$key : mixed

The key to replace.

$value : mixed

The value to set at $key.

Tags
inheritDoc
Return values
T|null

the previous value associated with key, or null if there was no mapping for $key.

replaceIf()

Replaces the entry for the specified key only if currently mapped to the specified value.

public replaceIf(mixed $key, mixed $oldValue, mixed $newValue) : bool
Parameters
$key : mixed

The key to remove from the map.

$oldValue : mixed

The value to match.

$newValue : mixed

The value to use as a replacement.

Tags
inheritDoc
Return values
bool

true if the value was replaced.

serialize()

Returns a serialized string representation of this array object.

public serialize() : string
Tags
deprecated

The Serializable interface will go away in PHP 9.

link

Serializable::serialize()

Return values
string

a PHP serialized string.

toArray()

Returns a native PHP array representation of this array object.

public toArray() : array<array-key, T>
Tags
inheritDoc
Return values
array<array-key, T>

unserialize()

Converts a serialized string representation into an instance object.

public unserialize(string $serialized) : void
Parameters
$serialized : string

A PHP serialized string to unserialize.

Tags
deprecated

The Serializable interface will go away in PHP 9.

link

Serializable::unserialize()

phpcsSuppress

SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint

Return values
void

checkType()

Returns `true` if value is of the specified type.

protected checkType(string $type, mixed $value) : bool
Parameters
$type : string

The type to check the value against.

$value : mixed

The value to check.

Return values
bool

toolValueToString()

Returns a string representation of the value.

protected toolValueToString(mixed $value) : string
  • null value: 'NULL'
  • boolean: 'TRUE', 'FALSE'
  • array: 'Array'
  • scalar: converted-value
  • resource: '(type resource #number)'
  • object with __toString(): result of __toString()
  • object DateTime: ISO 8601 date
  • object: '(className Object)'
  • anonymous function: same as object
Parameters
$value : mixed

the value to return as a string.

Return values
string

Search results