class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface (View source)

Defines the configuration object factory.

The configuration object factory instantiates a Config object for each configuration object name that is accessed and returns it to callers.

Properties

protected StorageInterface $storage

A storage instance for reading and writing configuration data.

protected EventDispatcherInterface $eventDispatcher

An event dispatcher instance to use for configuration events.

protected Config[] $cache

Cached configuration objects.

protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

protected ConfigFactoryOverrideInterface[] $configFactoryOverrides

An array of config factory override objects ordered by priority.

Methods

__construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config)

Constructs the Config factory.

getEditable(string $name)

Returns a mutable configuration object for a given name.

get(string $name)

Returns an immutable configuration object for a given name.

doGet(string $name, bool $immutable = TRUE)

Returns a configuration object for a given name.

loadMultiple(array $names)

Returns a list of configuration objects for the given names.

doLoadMultiple(array $names, bool $immutable = TRUE)

Returns a list of configuration objects for the given names.

array
loadOverrides(array $names)

Get arbitrary overrides for the named configuration objects from modules.

propagateConfigOverrideCacheability(string $cache_key, string $name)

Propagates cacheability of config overrides to cached config objects.

$this
reset(string|null $name = NULL)

Resets and re-initializes configuration objects. Internal use only.

$this
rename(string $old_name, string $new_name)

Renames a configuration object using the storage.

array
getCacheKeys()

The cache keys associated with the state of the config factory.

string
getConfigCacheKey(string $name, bool $immutable)

Gets the static cache key for a given config name.

array
getConfigCacheKeys(string $name)

Gets all the cache keys that match the provided config name.

$this
clearStaticCache()

Clears the config factory static cache.

array
listAll(string $prefix = '')

Gets configuration object names starting with a given prefix.

onConfigSave(ConfigCrudEvent $event)

Updates stale static cache entries when configuration is saved.

onConfigDelete(ConfigCrudEvent $event)

Removes stale static cache entries when configuration is deleted.

static 
getSubscribedEvents()

{@inheritdoc}

addOverride(ConfigFactoryOverrideInterface $config_factory_override)

Adds config factory override services.

createConfigObject(string $name, bool $immutable)

Creates a configuration object.

Details

__construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config)

Constructs the Config factory.

Parameters

StorageInterface $storage

The configuration storage engine.

EventDispatcherInterface $event_dispatcher

An event dispatcher instance to use for configuration events.

TypedConfigManagerInterface $typed_config

The typed configuration manager.

Config getEditable(string $name)

Returns a mutable configuration object for a given name.

Should not be used for config that will have runtime effects. Therefore it is always loaded override free.

Parameters

string $name

The name of the configuration object to construct.

Return Value

Config

A configuration object.

ImmutableConfig get(string $name)

Returns an immutable configuration object for a given name.

Parameters

string $name

The name of the configuration object to construct.

Return Value

ImmutableConfig

A configuration object.

protected Config|ImmutableConfig doGet(string $name, bool $immutable = TRUE)

Returns a configuration object for a given name.

Parameters

string $name

The name of the configuration object to construct.

bool $immutable

(optional) Create an immutable configuration object. Defaults to TRUE.

Return Value

Config|ImmutableConfig

A configuration object.

ImmutableConfig[] loadMultiple(array $names)

Returns a list of configuration objects for the given names.

This will pre-load all requested configuration objects does not create new configuration objects. This method always return immutable objects. ConfigFactoryInterface::getEditable() should be used to retrieve mutable configuration objects, one by one.

Parameters

array $names

List of names of configuration objects.

Return Value

ImmutableConfig[]

List of successfully loaded configuration objects, keyed by name.

protected Config[]|ImmutableConfig[] doLoadMultiple(array $names, bool $immutable = TRUE)

Returns a list of configuration objects for the given names.

Parameters

array $names

List of names of configuration objects.

bool $immutable

(optional) Create an immutable configuration objects. Defaults to TRUE.

Return Value

Config[]|ImmutableConfig[]

List of successfully loaded configuration objects, keyed by name.

protected array loadOverrides(array $names)

Get arbitrary overrides for the named configuration objects from modules.

Parameters

array $names

The names of the configuration objects to get overrides for.

Return Value

array

An array of overrides keyed by the configuration object name.

protected propagateConfigOverrideCacheability(string $cache_key, string $name)

Propagates cacheability of config overrides to cached config objects.

Parameters

string $cache_key

The key of the cached config object to update.

string $name

The name of the configuration object to construct.

$this reset(string|null $name = NULL)

Resets and re-initializes configuration objects. Internal use only.

Parameters

string|null $name

(optional) The name of the configuration object to reset. If omitted, all configuration objects are reset.

Return Value

$this

$this rename(string $old_name, string $new_name)

Renames a configuration object using the storage.

Parameters

string $old_name

The old name of the configuration object.

string $new_name

The new name of the configuration object.

Return Value

$this

array getCacheKeys()

The cache keys associated with the state of the config factory.

All state information that can influence the result of a get() should be included. Typically, this includes a key for each override added via addOverride(). This allows external code to maintain caches of configuration data in addition to or instead of caches maintained by the factory.

Return Value

array

An array of strings, used to generate a cache ID.

protected string getConfigCacheKey(string $name, bool $immutable)

Gets the static cache key for a given config name.

Parameters

string $name

The name of the configuration object.

bool $immutable

Whether or not the object is mutable.

Return Value

string

The cache key.

protected array getConfigCacheKeys(string $name)

Gets all the cache keys that match the provided config name.

Parameters

string $name

The name of the configuration object.

Return Value

array

An array of cache keys that match the provided config name.

$this clearStaticCache()

Clears the config factory static cache.

Return Value

$this

array listAll(string $prefix = '')

Gets configuration object names starting with a given prefix.

Parameters

string $prefix

(optional) The prefix to search for. If omitted, all configuration object names that exist are returned.

Return Value

array

An array containing matching configuration object names.

onConfigSave(ConfigCrudEvent $event)

Updates stale static cache entries when configuration is saved.

Parameters

ConfigCrudEvent $event

The configuration event.

onConfigDelete(ConfigCrudEvent $event)

Removes stale static cache entries when configuration is deleted.

Parameters

ConfigCrudEvent $event

The configuration event.

static getSubscribedEvents()

{@inheritdoc}

addOverride(ConfigFactoryOverrideInterface $config_factory_override)

Adds config factory override services.

Parameters

ConfigFactoryOverrideInterface $config_factory_override

The config factory override service to add. It is added at the end of the priority list (lower priority relative to existing ones).

protected Config|ImmutableConfig createConfigObject(string $name, bool $immutable)

Creates a configuration object.

Parameters

string $name

Configuration object name.

bool $immutable

Determines whether a mutable or immutable config object is returned.

Return Value

Config|ImmutableConfig

The configuration object.