class State implements StateInterface (View source)

Provides the state system using a key value store.

Properties

protected KeyValueStoreInterface $keyValueStore

The key value store to use.

protected array $cache

Static state cache.

Methods

__construct(KeyValueFactoryInterface $key_value_factory)

Constructs a State object.

mixed
get(string $key, mixed $default = NULL)

Returns the stored value for a given key.

array
getMultiple(array $keys)

Returns the stored key/value pairs for a given set of keys.

set(string $key, mixed $value)

Saves a value for a given key.

setMultiple(array $data)

Saves key/value pairs.

delete(string $key)

Deletes an item.

deleteMultiple(array $keys)

Deletes multiple items.

resetCache()

Resets the static cache.

Details

__construct(KeyValueFactoryInterface $key_value_factory)

Constructs a State object.

Parameters

KeyValueFactoryInterface $key_value_factory

The key value store to use.

mixed get(string $key, mixed $default = NULL)

Returns the stored value for a given key.

Parameters

string $key

The key of the data to retrieve.

mixed $default

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

Return Value

mixed

The stored value, or NULL if no value exists.

array getMultiple(array $keys)

Returns the stored key/value pairs for a given set of keys.

Parameters

array $keys

A list of keys to retrieve.

Return Value

array

An associative array of items successfully returned, indexed by key.

set(string $key, mixed $value)

Saves a value for a given key.

Parameters

string $key

The key of the data to store.

mixed $value

The data to store.

setMultiple(array $data)

Saves key/value pairs.

Parameters

array $data

An associative array of key/value pairs.

delete(string $key)

Deletes an item.

Parameters

string $key

The item name to delete.

deleteMultiple(array $keys)

Deletes multiple items.

Parameters

array $keys

A list of item names to delete.

resetCache()

Resets the static cache.

This is mainly used in testing environments.