class ConfigurationManager (View source)

A general purpose configuration manager

Constants

CONFIGURATION_TYPE_CACHES

Contains a list of caches which are registered automatically. Caches defined in this configuration file are registered in an early stage of the boot process and profit from mechanisms such as automatic flushing by the File Monitor. See the chapter about the Cache Framework for details.

CONFIGURATION_TYPE_OBJECTS

Contains object configuration, i.e. options which configure objects and the combination of those on a lower level. See the Object Framework chapter for more information.

CONFIGURATION_TYPE_ROUTES

Contains routes configuration. This routing information is parsed and used by the MVC Web Routing mechanism.

Refer to the Routing chapter for more information.

CONFIGURATION_TYPE_POLICY

Contains the configuration of the security policies of the system. See the Security chapter for details.

CONFIGURATION_TYPE_SETTINGS

Contains user-level settings, i.e. configuration options the users or administrators are meant to change.

Settings are the highest level of system configuration.

deprecated CONFIGURATION_PROCESSING_TYPE_DEFAULT

deprecated CONFIGURATION_PROCESSING_TYPE_OBJECTS

deprecated CONFIGURATION_PROCESSING_TYPE_POLICY

deprecated CONFIGURATION_PROCESSING_TYPE_ROUTES

deprecated CONFIGURATION_PROCESSING_TYPE_SETTINGS

deprecated CONFIGURATION_PROCESSING_TYPE_APPEND

Properties

protected LoaderInterface[] $configurationLoaders

Defines which Configuration Type is processed by which logic

protected ApplicationContext $context

The application context of the configuration to manage

protected array $configurations

Storage of the raw special configurations

protected FlowPackageInterface[] $packages

Active packages to load the configuration for

protected bool $cacheNeedsUpdate
protected string|null $temporaryDirectoryPath

An absolute file path to store configuration caches in. If not set, no cache will be active.

protected array $unprocessedConfiguration

Methods

__construct(ApplicationContext $context)

Constructs the configuration manager

void
setTemporaryDirectoryPath(string $temporaryDirectoryPath)

Set an absolute file path to store configuration caches in.

void
setPackages(array $packages)

Sets the active packages to load the configuration for

array
getAvailableConfigurationTypes()

Get the available configuration-types

void
registerConfigurationType(string $configurationType, LoaderInterface|string|null $configurationLoader = null)

Registers a new configuration type with the given source.

void
emitConfigurationManagerReady(ConfigurationManager $configurationManager)

Emits a signal after The ConfigurationManager has been loaded

mixed
getConfiguration(string $configurationType, string $configurationPath = null)

Returns the specified raw configuration.

void
shutdown()

Shuts down the configuration manager.

void
warmup()

Warms up the complete configuration cache, i.e. fetching every configured configuration type in order to be able to store it into the cache, if configured to do so.

void
loadConfiguration(string $configurationType, array $packages)

Loads special configuration defined in the specified packages and merges them with those potentially existing in the global configuration folders. The result is stored in the configuration manager's configuration registry and can be retrieved with the getConfiguration() method.

void
replaceConfigurationForConfigurationType(string $configurationType, string $cachePathAndFilename)

If a cache file with previously saved configuration exists, it is loaded.

void
loadConfigurationsFromCache()

Includes the cached configuration file such that $this->configurations is fully populated

void
flushConfigurationCache()

If a cache file with previously saved configuration exists, it is removed.

processConfigurationType(string $configurationType)

Generate configuration with environment variables replaced without modifying or loading the cache

void
saveConfigurationCache()

Saves the current configuration into a cache file and creates a cache inclusion script in the context's Configuration directory.

void
writeConfigurationCacheFile(string $cachePathAndFilename, string $configurationType = null)

Writes the cache on disk in the given cache file

void
refreshConfiguration()

No description

string
replaceVariablesInPhpString(string $phpString)

Replaces variables (in the format %CONSTANT% or %env:ENVIRONMENT_VARIABLE%) in the given php exported configuration string.

string
constructConfigurationCachePath()

Constructs a path to the configuration cache PHP file.

Details

__construct(ApplicationContext $context)

Constructs the configuration manager

Parameters

ApplicationContext $context

The application context to fetch configuration for

void setTemporaryDirectoryPath(string $temporaryDirectoryPath)

Set an absolute file path to store configuration caches in.

If never called no cache will be active.

Parameters

string $temporaryDirectoryPath

Return Value

void

void setPackages(array $packages)

Sets the active packages to load the configuration for

Parameters

array $packages

Return Value

void

array getAvailableConfigurationTypes()

Get the available configuration-types

Return Value

array

array of configuration-type identifier strings

void registerConfigurationType(string $configurationType, LoaderInterface|string|null $configurationLoader = null)

Registers a new configuration type with the given source.

Parameters

string $configurationType

The type to register, may be anything

LoaderInterface|string|null $configurationLoader

This should be an instance of LoaderInterface. For backwards compatibility reasons it might also be a string representing one of the CONFIGURATION_PROCESSINGTYPE* constants. If null, the default "MergeLoader" is used

Return Value

void

Exceptions

InvalidArgumentException

protected void emitConfigurationManagerReady(ConfigurationManager $configurationManager)

Emits a signal after The ConfigurationManager has been loaded

Parameters

ConfigurationManager $configurationManager

Return Value

void

mixed getConfiguration(string $configurationType, string $configurationPath = null)

Returns the specified raw configuration.

The actual configuration will be merged from different sources in a defined order.

Note that this is a low level method and mostly makes sense to be used by Flow internally. If possible just use settings and have them injected.

Parameters

string $configurationType

The kind of configuration to fetch - must be one of the CONFIGURATIONTYPE* constants

string $configurationPath

The path inside the configuration to fetch

Return Value

mixed

The configuration or NULL if the configuration doesn't exist

Exceptions

InvalidConfigurationTypeException

void shutdown()

Shuts down the configuration manager.

This method writes the current configuration into a cache file if Flow was configured to do so.

void warmup()

Warms up the complete configuration cache, i.e. fetching every configured configuration type in order to be able to store it into the cache, if configured to do so.

Return Value

void

Exceptions

InvalidConfigurationException

See also

ConfigurationManager::shutdown

protected void loadConfiguration(string $configurationType, array $packages)

Loads special configuration defined in the specified packages and merges them with those potentially existing in the global configuration folders. The result is stored in the configuration manager's configuration registry and can be retrieved with the getConfiguration() method.

Parameters

string $configurationType

The kind of configuration to load - must be one of the CONFIGURATIONTYPE* constants

array $packages

An array of Package objects (indexed by package key) to consider

Return Value

void

Exceptions

InvalidConfigurationTypeException

protected void replaceConfigurationForConfigurationType(string $configurationType, string $cachePathAndFilename)

If a cache file with previously saved configuration exists, it is loaded.

Parameters

string $configurationType

The kind of configuration to fetch

string $cachePathAndFilename

The cache file to load the configuration from

Return Value

void

protected void loadConfigurationsFromCache()

Includes the cached configuration file such that $this->configurations is fully populated

Return Value

void

void flushConfigurationCache()

If a cache file with previously saved configuration exists, it is removed.

Internal: After this the configuration manager is left without any configuration, use refreshConfiguration if you want to reread the configuration.

Return Value

void

Exceptions

Exception

See also

refreshConfiguration

protected processConfigurationType(string $configurationType)

Generate configuration with environment variables replaced without modifying or loading the cache

Parameters

string $configurationType

The kind of configuration to fetch

protected void saveConfigurationCache()

Saves the current configuration into a cache file and creates a cache inclusion script in the context's Configuration directory.

Return Value

void

Exceptions

InvalidConfigurationTypeException

protected void writeConfigurationCacheFile(string $cachePathAndFilename, string $configurationType = null)

Writes the cache on disk in the given cache file

Parameters

string $cachePathAndFilename

The file to save the cache

string $configurationType

Return Value

void

void refreshConfiguration()

No description

Return Value

void

Exceptions

InvalidConfigurationTypeException

protected string replaceVariablesInPhpString(string $phpString)

Replaces variables (in the format %CONSTANT% or %env:ENVIRONMENT_VARIABLE%) in the given php exported configuration string.

This is applied before caching to allow runtime evaluation of constants and environment variables.

Parameters

string $phpString

Return Value

string

protected string constructConfigurationCachePath()

Constructs a path to the configuration cache PHP file.

Derived from the temporary path and application context.

Return Value

string