Documentation

Settings
in package

Application settings management.

Provides methods for reading, writing, and managing application settings stored in the database, as well as LWT general table operations.

Tags
since
3.0.0

Table of Contents

Methods

get()  : string
Get a setting from the database. It can also check for its validity.
getWithDefault()  : string
Get the settings value for a specific key. Return a default value when possible.
getZeroOrOne()  : int
Convert a setting to 0 or 1.
lwtTableCheck()  : void
Check if the _lwtgeneral table exists, create it if not.
lwtTableGet()  : string
Get a value from the _lwtgeneral table.
lwtTableSet()  : void
Set a value in the _lwtgeneral table.
save()  : void
Save the setting identified by a key with a specific value.
saveForUser()  : void
Save a user-scoped setting for a specific user.
savePerUser()  : void
Save a setting under the current user's scope when multi-user mode is enabled, or globally otherwise.

Methods

get()

Get a setting from the database. It can also check for its validity.

public static get(string $key) : string
Parameters
$key : string

Setting key. If $key is 'currentlanguage' or 'currenttext', we validate language/text.

Return values
string

Value in the database if found, or an empty string

getWithDefault()

Get the settings value for a specific key. Return a default value when possible.

public static getWithDefault(string $key) : string

In multi-user mode, user-scoped settings are checked for the current user first, then fall through to the hardcoded default — never to the global StUsID=0 row, since that would leak the prior user's choice into a fresh account. Admin-scoped settings still fall back to StUsID=0 (that row is how admins set system-wide values), and single-user mode (no current user) keeps the original StUsID=0 → hardcoded-default chain.

Parameters
$key : string

Settings key

Return values
string

Requested setting, or default value, or ''

getZeroOrOne()

Convert a setting to 0 or 1.

public static getZeroOrOne(string $key, string|int $dft) : int
Parameters
$key : string

The setting key

$dft : string|int

Default value to use, should be convertible to string

Tags
psalm-return

0|1

Return values
int

lwtTableCheck()

Check if the _lwtgeneral table exists, create it if not.

public static lwtTableCheck() : void

lwtTableGet()

Get a value from the _lwtgeneral table.

public static lwtTableGet(string $key) : string
Parameters
$key : string

Key to retrieve

Return values
string

Value or empty string if not found

lwtTableSet()

Set a value in the _lwtgeneral table.

public static lwtTableSet(string $key, string $val) : void
Parameters
$key : string

Key to set

$val : string

Value to store

save()

Save the setting identified by a key with a specific value.

public static save(string $k, mixed $v) : void
Parameters
$k : string

Setting key

$v : mixed

Setting value, will get converted to string

Tags
throws
InvalidArgumentException

If value is not set or is empty

saveForUser()

Save a user-scoped setting for a specific user.

public static saveForUser(string $k, mixed $v, int $userId) : void

Uses StUsID = $userId for per-user storage.

Parameters
$k : string

Setting key

$v : mixed

Setting value

$userId : int

User ID

savePerUser()

Save a setting under the current user's scope when multi-user mode is enabled, or globally otherwise.

public static savePerUser(string $k, mixed $v) : void

Settings::get() already reads through QueryBuilder, which auto-scopes the settings table; in multi-user mode that means a Settings::save to StUsID=0 is invisible to the reader and the value is silently lost (or worse, overwrites the global default seen by users with no per-user row). This helper picks the matching write path so reads find the value the current request just stored.

Parameters
$k : string

Setting key

$v : mixed

Setting value, will get converted to string


        
On this page

Search results