PHP Интерфейс Webmozart\KeyValueStore\Api\KeyValueStore

KeyUtil-value stores support storing values for integer or string keys chosen by the user. Any serializable value can be stored, although an implementation of this interface may further restrict the range of accepted values. See the documentation of the implementation for more information.
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования интерфейса

Открытые методы

Метод Описание
clear ( ) Removes all keys from the store.
exists ( integer | string $key ) : boolean Returns whether a key exists.
get ( integer | string $key, mixed $default = null ) : mixed Returns the value of a key in the store.
getMultiple ( array $keys, mixed $default = null ) : array Returns the values of multiple keys in the store.
getMultipleOrFail ( array $keys ) : array Returns the values of multiple keys in the store.
getOrFail ( integer | string $key ) : mixed Returns the value of a key in the store.
keys ( ) : array Returns all keys currently stored in the store.
remove ( integer | string $key ) : boolean Removes a key from the store.
set ( integer | string $key, mixed $value ) Sets the value for a key in the store.

Описание методов

clear() публичный Метод

If the backend of the store cannot be written, a {@link WriteException} is thrown. You should always handle this exception in your code: php try { $store->clear(); } catch (WriteException $e) { write failed }
public clear ( )

exists() публичный Метод

Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { if ($store->exists($key)) { ... } } catch (ReadException $e) { read failed }
public exists ( integer | string $key ) : boolean
$key integer | string The key to test.
Результат boolean Whether the key exists in the store.

get() публичный Метод

If a key does not exist in the store, the default value passed in the second parameter is returned. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { $value = $store->get($key); } catch (ReadException $e) { read failed }
public get ( integer | string $key, mixed $default = null ) : mixed
$key integer | string The key to get.
$default mixed The default value to return if the key does not exist.
Результат mixed The value of the key or the default value if the key does not exist.

getMultiple() публичный Метод

The passed default value is returned for keys that don't exist. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { $value = $store->getMultiple(array($key1, $key2)); } catch (ReadException $e) { read failed }
public getMultiple ( array $keys, mixed $default = null ) : array
$keys array The keys to get. The keys must be strings or integers.
$default mixed The default value to return for keys that are not found.
Результат array The values of the passed keys, indexed by the keys.

getMultipleOrFail() публичный Метод

If a key does not exist in the store, an exception is thrown. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { $value = $store->getMultipleOrFail(array($key1, $key2)); } catch (ReadException $e) { read failed }
public getMultipleOrFail ( array $keys ) : array
$keys array The keys to get. The keys must be strings or integers.
Результат array The values of the passed keys, indexed by the keys.

getOrFail() публичный Метод

If the key does not exist in the store, an exception is thrown. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { $value = $store->getOrFail($key); } catch (ReadException $e) { read failed }
public getOrFail ( integer | string $key ) : mixed
$key integer | string The key to get.
Результат mixed The value of the key.

keys() публичный Метод

If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { foreach ($store->keys() as $key) { ... } } catch (ReadException $e) { read failed }
public keys ( ) : array
Результат array The keys stored in the store. Each key is either a string or an integer. The order of the keys is undefined.

remove() публичный Метод

If the store does not contain the key, this method returns false. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be written, a {@link WriteException} is thrown. You should always handle this exception in your code: php try { $store->remove($key); } catch (WriteException $e) { write failed }
public remove ( integer | string $key ) : boolean
$key integer | string The key to remove.
Результат boolean Returns `true` if a key was removed from the store.

set() публичный Метод

The key-value store accepts any serializable value. If a value is not serializable, a {@link SerializationFailedException} is thrown. Additionally, implementations may put further restrictions on their accepted values. If an unsupported value is passed, an {@link UnsupportedValueException} is thrown. Check the documentation of the implementation to learn more about its supported values. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be written, a {@link WriteException} is thrown. You should always handle this exception in your code: php try { $store->set($key, $value); } catch (WriteException $e) { write failed }
public set ( integer | string $key, mixed $value )
$key integer | string The key to set.
$value mixed The value to set for the key.