Documentation

SettingsManager

Class SettingsManager

Tags
see
SettingsManagerTest

Table of Contents

Constants

BOOT_PHASE_COMPLETE  = 2
BOOT_PHASE_EARLY  = 0
BOOT_PHASE_MID  = 1

Properties

$bagsByContact  : array<string|int, mixed>
$bagsByDomain  : array<string|int, mixed>
$bootPhase  : int
The SettingsManager boots through 3 phases:
$cache  : CRM_Utils_Cache_Interface
$mandatory  : array<string|int, mixed>|null

Methods

__construct()  : mixed
bootComplete()  : SettingsManager
Remove pre-boot restrictions and reload defaults/mandatory
bootSettings()  : mixed
Load boot settings from environment and/or settings file
dbAvailable()  : SettingsManager
Signal that the SettingsManager can now load values from the DB
flush()  : SettingsManager
Flush all in-memory and persistent caches related to settings.
getBagByContact()  : SettingsBag
Get Settings by contact.
getBagByDomain()  : SettingsBag
Get Settings by domain.
parseMandatorySettingsGlobalVar()  : array<string|int, mixed>
Parse mandatory settings from global env var.
useDefaults()  : SettingsManager
Maintained as public alias of bootComplete for compatibility
useMandatory()  : SettingsManager
Ensure that mandatory values are included with all current and future bags.
getDefaults()  : array<string|int, mixed>
Determine the default settings.
getEnvSettingValues()  : array<string|int, mixed>
Get any setting values set using environment variables
getMandatory()  : array<string|int, mixed>
Get a list of mandatory/overriden settings from $civicrm_setting global or environment.
reloadDefaults()  : SettingsManager
(Re)load default values for all existing settings bags
reloadValues()  : SettingsManager
(Re)load database values for all existing settings bags

Constants

Properties

$bagsByContact

protected array<string|int, mixed> $bagsByContact = []

Array (int $id => SettingsBag $bag).

$bagsByDomain

protected array<string|int, mixed> $bagsByDomain = []

Array (int $id => SettingsBag $bag).

$bootPhase

The SettingsManager boots through 3 phases:

protected int $bootPhase = self::BOOT_PHASE_EARLY
  1. during early boot, we load metadata for a limited subset of settings in core *.boot.setting.php files. Setting values come only from environment variables, $civicrm_setting global, or default

  2. once the database is loaded, we can load database values

  3. once the extension system is booted, we have full and final settings metadata (including from extensions)

$mandatory

protected array<string|int, mixed>|null $mandatory = NULL

Array(string $entity => array(string $settingName => mixed $value)). Ex: $mandatory['domain']['uploadDir']. NULL means "autoload from $civicrm_setting".

Methods

bootSettings()

Load boot settings from environment and/or settings file

public static bootSettings(string $settingsPath) : mixed
Parameters
$settingsPath : string

Path to the civicrm.settings.php file

getBagByContact()

Get Settings by contact.

public getBagByContact(int|null $domainId, int|null $contactId) : SettingsBag
Parameters
$domainId : int|null

For the default domain, leave $domainID as NULL.

$contactId : int|null

For the default/active user's contact, leave $domainID as NULL.

Tags
throws
CRM_Core_Exception

If there is no contact, then there's no SettingsBag, and we'll throw an exception.

Return values
SettingsBag

parseMandatorySettingsGlobalVar()

Parse mandatory settings from global env var.

public static parseMandatorySettingsGlobalVar(array<string|int, mixed> $civicrm_setting) : array<string|int, mixed>

In previous versions, settings were broken down into verbose+dynamic group names, e.g.

$civicrm_settings['Foo Bar Preferences']['foo'] = 'bar';

We now simplify to two simple groups, 'domain' and 'contact'.

$civicrm_settings['domain']['foo'] = 'bar';

'Personal Preferences' is still aliased for compatibility (is this still needed in June 2024?).

Parameters
$civicrm_setting : array<string|int, mixed>

Ex: $civicrm_setting['Group Name']['field'] = 'value'. Group names are an historical quirk; ignore them.

Return values
array<string|int, mixed>

useMandatory()

Ensure that mandatory values are included with all current and future bags.

public useMandatory() : SettingsManager

If you call useMandatory multiple times, it will re-scan the global $civicrm_setting and environment variables

Return values
SettingsManager

getDefaults()

Determine the default settings.

protected getDefaults(string $entity) : array<string|int, mixed>
Parameters
$entity : string

Ex: 'domain' or 'contact'.

Return values
array<string|int, mixed>

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

getEnvSettingValues()

Get any setting values set using environment variables

protected getEnvSettingValues(string $entity) : array<string|int, mixed>
Parameters
$entity : string

Ex: 'domain' or 'contact'.

Return values
array<string|int, mixed>

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

getMandatory()

Get a list of mandatory/overriden settings from $civicrm_setting global or environment.

protected getMandatory(string $entity) : array<string|int, mixed>
Parameters
$entity : string

Ex: 'domain' or 'contact'.

Return values
array<string|int, mixed>

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


        
On this page

Search results