PHP Interface 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.
Since: 1.0
Author: Bernhard Schussek ([email protected])
Exibir arquivo Open project: webmozart/key-value-store Interface Usage Examples

Public Methods

Method Description
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.

Method Details

clear() public method

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() public method

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.
return boolean Whether the key exists in the store.

get() public method

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.
return mixed The value of the key or the default value if the key does not exist.

getMultiple() public method

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.
return array The values of the passed keys, indexed by the keys.

getMultipleOrFail() public method

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.
return array The values of the passed keys, indexed by the keys.

getOrFail() public method

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.
return mixed The value of the key.

keys() public method

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
return array The keys stored in the store. Each key is either a string or an integer. The order of the keys is undefined.

remove() public method

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.
return boolean Returns `true` if a key was removed from the store.

set() public method

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.