Documentation

SettingsBag

Class SettingsBag

Tags
see
Civi::settings()
see
SettingsManagerTest

Table of Contents

Properties

$combined  : array<string|int, mixed>|null
The result of combining default values, mandatory values, and user values.
$contactId  : mixed
$defaults  : array<string|int, mixed>
$domainId  : mixed
$mandatory  : array<string|int, mixed>
$values  : array<string|int, mixed>

Methods

__construct()  : mixed
add()  : SettingsBag
Add a batch of settings. Save them.
all()  : array<string|int, mixed>
Get a list of all effective settings.
computeVirtual()  : array<string|int, mixed>
Determine the values of any virtual/computed settings.
get()  : mixed
Determine the effective value.
getContributionInvoiceSettingKeys()  : array<string|int, mixed>
getDefault()  : mixed|null
Determine the default value of a setting.
getExplicit()  : mixed|null
Determine the explicitly designated value, regardless of any default or mandatory values.
getMandatory()  : mixed|null
Determine the mandatory value of a setting.
hasExplict()  : bool
Determine if the entity has explicitly designated a value.
loadDefaults()  : SettingsBag
Set/replace the default values.
loadMandatory()  : SettingsBag
Set/replace the mandatory values.
loadValues()  : SettingsBag
Load all explicit settings that apply to this domain or contact.
revert()  : SettingsBag
Removes any explicit settings. This restores the default.
set()  : SettingsBag
Add a single setting. Save it.
updateVirtual()  : bool
Update a virtualized/deprecated setting.
combine()  : array<string|int, mixed>
Combine a series of arrays, excluding any null values. Later values override earlier values.
createQuery()  : CRM_Utils_SQL_Select
interpolateDsnSettings()  : array<string|int, mixed>
Compute a missing DSN from its component parts or vice versa
setDb()  : mixed
Update the DB record for this setting.

Properties

$combined

The result of combining default values, mandatory values, and user values.

protected array<string|int, mixed>|null $combined

Array(string $settingName => mixed $value).

$defaults

protected array<string|int, mixed> $defaults

Array(string $settingName => mixed $value).

$mandatory

protected array<string|int, mixed> $mandatory

Array(string $settingName => mixed $value).

Methods

__construct()

public __construct(int $domainId, int|null $contactId) : mixed
Parameters
$domainId : int

The domain for which we want settings.

$contactId : int|null

The contact for which we want settings. Use NULL for domain settings.

add()

Add a batch of settings. Save them.

public add(array<string|int, mixed> $settings) : SettingsBag
Parameters
$settings : array<string|int, mixed>

Array(string $settingName => mixed $settingValue).

Return values
SettingsBag

all()

Get a list of all effective settings.

public all() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array(string $settingName => mixed $settingValue).

computeVirtual()

Determine the values of any virtual/computed settings.

public computeVirtual() : array<string|int, mixed>
Return values
array<string|int, mixed>

get()

Determine the effective value.

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

getContributionInvoiceSettingKeys()

public static getContributionInvoiceSettingKeys() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDefault()

Determine the default value of a setting.

public getDefault(string $key) : mixed|null
Parameters
$key : string

The simple name of the setting.

Return values
mixed|null

getExplicit()

Determine the explicitly designated value, regardless of any default or mandatory values.

public getExplicit(string $key) : mixed|null
Parameters
$key : string

The simple name of the setting.

Return values
mixed|null

getMandatory()

Determine the mandatory value of a setting.

public getMandatory(string $key) : mixed|null
Parameters
$key : string

The simple name of the setting.

Return values
mixed|null

hasExplict()

Determine if the entity has explicitly designated a value.

public hasExplict(string $key) : bool

Note that get() may still return other values based on mandatory values or defaults.

Parameters
$key : string

The simple name of the setting.

Return values
bool

loadDefaults()

Set/replace the default values.

public loadDefaults(array<string|int, mixed> $defaults) : SettingsBag
Parameters
$defaults : array<string|int, mixed>

Array(string $settingName => mixed $value).

Return values
SettingsBag

loadMandatory()

Set/replace the mandatory values.

public loadMandatory(array<string|int, mixed> $mandatory) : SettingsBag
Parameters
$mandatory : array<string|int, mixed>

Array(string $settingName => mixed $value).

Return values
SettingsBag

revert()

Removes any explicit settings. This restores the default.

public revert(string $key) : SettingsBag
Parameters
$key : string

The simple name of the setting.

Return values
SettingsBag

set()

Add a single setting. Save it.

public set(string $key, mixed $value) : SettingsBag
Parameters
$key : string

The simple name of the setting.

$value : mixed

The new, explicit value of the setting.

Return values
SettingsBag

updateVirtual()

Update a virtualized/deprecated setting.

public updateVirtual(string $key, array<string|int, mixed> $value) : bool

Temporary handling for phasing out contribution_invoice_settings.

Until we have transitioned we need to handle setting & retrieving contribution_invoice_settings.

Once removed from core we will add deprecation notices & then remove this.

https://lab.civicrm.org/dev/core/issues/1558

Parameters
$key : string
$value : array<string|int, mixed>
Return values
bool

TRUE if $key is a virtualized setting. FALSE if it is a normal setting.

combine()

Combine a series of arrays, excluding any null values. Later values override earlier values.

protected combine(array<string|int, mixed> $arrays) : array<string|int, mixed>
Parameters
$arrays : array<string|int, mixed>

List of arrays to combine.

Return values
array<string|int, mixed>

interpolateDsnSettings()

Compute a missing DSN from its component parts or vice versa

protected interpolateDsnSettings(string $prefix) : array<string|int, mixed>

Note: defaults for civicrm_db_XXX will be used

Parameters
$prefix : string

The prefix of the DB setting group - ex: 'civicrm' or 'civicrm_uf'

Return values
array<string|int, mixed>

Ex 1:

$prefix = 'civicrm' civicrm_db_dsn is NOT already set civicrm_db_user set to 'james' civicrm_db_password set to 'i<3#browns'

returns [ 'civicrm_db_dsn' => 'mysql://james:i%3C3%23browns@localhost:3306/civicrm', ]

Ex 2:

$prefix = 'civicrm_uf', civicrm_uf_db_dsn is set to 'mysql://my_user!:pass#word@host.name/db_name'

returns [ 'civicrm_uf_db_user' => 'my_user!', 'civicrm_uf_db_password' => 'pass#word', 'civicrm_uf_db_host' => 'host.name', 'civicrm_uf_db_database' => 'db_name', ]

setDb()

Update the DB record for this setting.

protected setDb(string $name, mixed $value) : mixed
Parameters
$name : string

The simple name of the setting.

$value : mixed

The new value of the setting.


        
On this page

Search results