final class Settings (View source)

Read only settings that are initialized with the class.

Methods

__construct(array $settings)

Constructor.

static Settings
getInstance()

Returns the settings instance.

__sleep()

Prevents settings from being serialized.

static mixed
get(string $name, mixed $default = NULL)

Returns a setting.

static array
getAll()

Returns all the settings. This is only used for testing purposes.

static 
initialize(string $app_root, string $site_path, ClassLoader $class_loader)

Bootstraps settings.php and the Settings singleton.

static string
getHashSalt()

Gets a salt useful for hardening against SQL injection.

static string
getApcuPrefix(string $identifier, string $root, string $site_path = '')

Generates a prefix for APCu user cache keys.

Details

__construct(array $settings)

Constructor.

Parameters

array $settings

Array with the settings.

static Settings getInstance()

Returns the settings instance.

A singleton is used because this class is used before the container is available.

Return Value

Settings

Exceptions

BadMethodCallException

__sleep()

Prevents settings from being serialized.

static mixed get(string $name, mixed $default = NULL)

Returns a setting.

Settings can be set in settings.php in the $settings array and requested by this function. Settings should be used over configuration for read-only, possibly low bootstrap configuration that is environment specific.

Parameters

string $name

The name of the setting to return.

mixed $default

(optional) The default value to use if this setting is not set.

Return Value

mixed

The value of the setting, the provided default if not set.

static array getAll()

Returns all the settings. This is only used for testing purposes.

Return Value

array

All the settings.

static initialize(string $app_root, string $site_path, ClassLoader $class_loader)

Bootstraps settings.php and the Settings singleton.

Parameters

string $app_root

The app root.

string $site_path

The current site path.

ClassLoader $class_loader

The class loader that is used for this request. Passed by reference and exposed to the local scope of settings.php, so as to allow it to be decorated.

See also

default.settings.php

static string getHashSalt()

Gets a salt useful for hardening against SQL injection.

Return Value

string

A salt based on information in settings.php, not in the database.

Exceptions

RuntimeException

static string getApcuPrefix(string $identifier, string $root, string $site_path = '')

Generates a prefix for APCu user cache keys.

A standardized prefix is useful to allow visual inspection of an APCu user cache. By default, this method will produce a unique prefix per site using the hash salt. If the setting 'apcu_ensure_unique_prefix' is set to FALSE then if the caller does not provide a $site_path only the Drupal root will be used. This allows tests to use the same prefix ensuring that the number of APCu items created during a full test run is kept to a minimum. Additionally, if a multi site implementation does not use site specific module directories setting apcu_ensure_unique_prefix would allow the sites to share APCu cache items.

Parameters

string $identifier

An identifier for the prefix. For example, 'class_loader' or 'cache_backend'.

string $root

The app root.

string $site_path

(optional) The site path. Defaults to an empty string.

Return Value

string

The prefix for APCu user cache keys.

See also

https://www.drupal.org/project/drupal/issues/2926309