class db extends config

Configuration container class

Properties

protected array<string,string> $config

The configuration data

from  config
protected driver_interface $cache

Cache instance

protected driver_interface $db

Database connection

protected string $table

Name of the database table used for configuration.

Methods

__construct(driver_interface $db, driver_interface $cache, string $table)

Creates a configuration container with a default set of values

getIterator()

Retrieves an ArrayIterator over the configuration values.

from  config
bool
offsetExists(string $key)

Checks if the specified config value exists.

from  config
string
offsetGet(string $key)

Retrieves a configuration value.

from  config
offsetSet(string $key, string $value)

Temporarily overwrites the value of a configuration variable.

from  config
offsetUnset(string $key)

Called when deleting a configuration value directly, triggers an error.

from  config
int
count()

Retrieves the number of configuration options currently set.

from  config
null
delete(string $key, bool $use_cache = true)

Removes a configuration option

set(string $key, string $value, bool $use_cache = true)

Sets a configuration option's value

bool
set_atomic(string $key, string $old_value, string $new_value, bool $use_cache = true)

Sets a configuration option's value only if the old_value matches the current configuration value or the configuration value does not exist yet.

bool
ensure_lock(string $key, string $new_value)

Checks configuration option's value only if the new_value matches the current configuration value and the configuration value does exist.Called only after set_atomic has been called.

from  config
increment(string $key, int $increment, bool $use_cache = true)

Increments an integer config value directly in the database.

initialise(driver_interface $cache)

Initialise config with database and/or cached entries

Details

at line 49
__construct(driver_interface $db, driver_interface $cache, string $table)

Creates a configuration container with a default set of values

Parameters

driver_interface $db

Database connection

driver_interface $cache

Cache instance

string $table

Configuration table name

in config at line 42
ArrayIterator getIterator()

Retrieves an ArrayIterator over the configuration values.

Return Value

ArrayIterator

An iterator over all config data

in config at line 53
bool offsetExists(string $key)

Checks if the specified config value exists.

Parameters

string $key

The configuration option's name.

Return Value

bool

Whether the configuration option exists.

in config at line 64
string offsetGet(string $key)

Retrieves a configuration value.

Parameters

string $key

The configuration option's name.

Return Value

string

The configuration value

in config at line 78
offsetSet(string $key, string $value)

Temporarily overwrites the value of a configuration variable.

The configuration change will not persist. It will be lost after the request.

Parameters

string $key

The configuration option's name.

string $value

The temporary value.

in config at line 88
offsetUnset(string $key)

Called when deleting a configuration value directly, triggers an error.

Parameters

string $key

The configuration option's name.

in config at line 98
int count()

Retrieves the number of configuration options currently set.

Return Value

int

Number of config options

at line 113
null delete(string $key, bool $use_cache = true)

Removes a configuration option

Parameters

string $key

The configuration option's name

bool $use_cache

Whether this variable should be cached or if it changes too frequently to be efficiently cached

Return Value

null

at line 135
set(string $key, string $value, bool $use_cache = true)

Sets a configuration option's value

Parameters

string $key

The configuration option's name

string $value

New configuration value

bool $use_cache

Whether this variable should be cached or if it changes too frequently to be efficiently cached.

at line 152
bool set_atomic(string $key, string $old_value, string $new_value, bool $use_cache = true)

Sets a configuration option's value only if the old_value matches the current configuration value or the configuration value does not exist yet.

Parameters

string $key

The configuration option's name

string $old_value

Current configuration value

string $new_value

New configuration value

bool $use_cache

Whether this variable should be cached or if it changes too frequently to be efficiently cached.

Return Value

bool

True if the value was changed, false otherwise.

in config at line 160
bool ensure_lock(string $key, string $new_value)

Checks configuration option's value only if the new_value matches the current configuration value and the configuration value does exist.Called only after set_atomic has been called.

Parameters

string $key

The configuration option's name

string $new_value

New configuration value

Return Value

bool

True if the value was changed, false otherwise.

Exceptions

http_exception

when config value is set and not equal to new_value.

at line 199
increment(string $key, int $increment, bool $use_cache = true)

Increments an integer config value directly in the database.

Using this method instead of setting the new value directly avoids race conditions and unlike set_atomic it cannot fail.

Parameters

string $key

The configuration option's name

int $increment

Amount to increment by

bool $use_cache

Whether this variable should be cached or if it changes too frequently to be efficiently cached.

at line 65
initialise(driver_interface $cache)

Initialise config with database and/or cached entries

Parameters

driver_interface $cache