‪TYPO3CMS  9.5
TYPO3\CMS\Core\Configuration\ExtensionConfiguration Class Reference

Public Member Functions

mixed get (string $extension, string $path='')
 
 set (string $extension, string $path='', $value=null)
 
 setAll (array $configuration)
 
 synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions ()
 
 synchronizeExtConfTemplateWithLocalConfiguration (string $extensionKey)
 
array getParsedExtConfTemplate (string $extensionKey)
 

Protected Member Functions

array getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots (string $extensionKey)
 
string getDefaultConfigurationRawString (string $extensionKey)
 
array removeCommentsAndDotsRecursive (array $config)
 
 parseSub (array &$setup)
 
 rollParseSub ($string, array &$setup)
 
 setVal ($string, array &$setup, $value)
 
array parseNextKeySegment ($key)
 

Protected Attributes

array $setup = array( )
 
array $raw
 
int $rawPointer = 0
 
string $lastComment = ''
 
bool $commentSet = false
 
int $inBrace = 0
 

Private Member Functions

array addDotsToArrayKeysRecursiveForLegacyExtConf (array $extensionConfig)
 

Detailed Description

API to get() instance specific extension configuration options.

Extension authors are encouraged to use this API - it is currently a simple wrapper to access TYPO3_CONF_VARS['EXTENSIONS'] but could later become something different in case core decides to store extension configuration elsewhere.

Extension authors must not access TYPO3_CONF_VARS['EXTENSIONS'] on their own.

Extension configurations are often 'feature flags' currently defined by ext_conf_template.txt files. The core (more specifically the install tool) takes care default values and overridden values are properly prepared upon loading or updating an extension.

Note only ->get() is official API and other public methods are low level core internal API that is usually only used by extension manager and install tool.

Definition at line 41 of file ExtensionConfiguration.php.

Member Function Documentation

◆ addDotsToArrayKeysRecursiveForLegacyExtConf()

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::addDotsToArrayKeysRecursiveForLegacyExtConf ( array  $extensionConfig)
private

The old EXT/extConf layer had '.' (dots) at the end of all nested array keys. This is created here to keep EXT/extConf format compatible with old not yet adapted extensions. But extensions may rely on ending dots if using legacy unserialize() on their extensions, too.

A EXTENSIONS array like: TYPO3_CONF_VARS['EXTENSIONS']['someExtension'] => [ 'someKey' => [ 'someSubKey' => [ 'someSubSubKey' => 'someValue', ], ], ] becomes (serialized) in old EXT/extConf (mind the dots and end of array keys for sub arrays): TYPO3_CONF_VARS['EXTENSIONS']['someExtension'] => [ 'someKey.' => [ 'someSubKey.' => [ 'someSubSubKey' => 'someValue', ], ], ]

Parameters
array$extensionConfig
Returns
‪array
Deprecated:
‪since TYPO3 v9, will be removed in TYPO3 v10.0 with removal of old serialized 'extConf' layer

Definition at line 329 of file ExtensionConfiguration.php.

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\set(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\setAll().

◆ get()

mixed TYPO3\CMS\Core\Configuration\ExtensionConfiguration::get ( string  $extension,
string  $path = '' 
)

Get a single configuration value, a sub array or the whole configuration.

Examples: // Simple and typical usage: Get a single config value, or an array if the key is a "TypoScript" // a-like sub-path in ext_conf_template.txt "foo.bar = defaultValue" ->get('myExtension', 'aConfigKey');

// Get all current configuration values, always an array ->get('myExtension');

// Get a nested config value if the path is a "TypoScript" a-like sub-path // in ext_conf_template.txt "topLevelKey.subLevelKey = defaultValue" ->get('myExtension', 'topLevelKey/subLevelKey')

Notes:

  • ‪If a configuration or configuration path of an extension is not found, the code tries to synchronize configuration with ext_conf_template.txt first, only if still not found, it will throw exceptions.
  • ‪Return values are NOT type safe: A boolean false could be returned as string 0. Cast accordingly.
  • ‪This API throws exceptions if the path does not exist or the extension configuration is not available. The install tool takes care any new ext_conf_template.txt values are available TYPO3_CONF_VARS['EXTENSIONS'], a thrown exception indicates a programming error on developer side and should not be caught.
  • ‪It is not checked if the extension in question is loaded at all, it's just checked the extension configuration path exists.
  • ‪Extensions should typically not get configuration of a different extension.
Parameters
string$extension‪Extension name
string$pathConfiguration path - eg. "featureCategory/coolThingIsEnabled"
Returns
‪mixed The value. Can be a sub array or a single value.
Exceptions
ExtensionConfigurationExtensionNotConfiguredException‪If ext configuration does no exist
ExtensionConfigurationPathDoesNotExistException‪If a requested extension path does not exist

Definition at line 121 of file ExtensionConfiguration.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath(), TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions().

◆ getDefaultConfigurationRawString()

string TYPO3\CMS\Core\Configuration\ExtensionConfiguration::getDefaultConfigurationRawString ( string  $extensionKey)
protected

Helper method of ext_conf_template.txt parsing.

Return content of an extensions ext_conf_template.txt file if the file exists, empty string if file does not exist.

Parameters
string$extensionKey‪Extension key
Returns
‪string

Definition at line 395 of file ExtensionConfiguration.php.

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getParsedExtConfTemplate().

◆ getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots()

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots ( string  $extensionKey)
protected

Helper method of ext_conf_template.txt parsing.

Poor man version of getDefaultConfigurationFromExtConfTemplateAsValuedArray() which ignores comments and returns ext_conf_template as array where nested keys have no dots.

Parameters
string$extensionKey
Returns
‪array

Definition at line 351 of file ExtensionConfiguration.php.

References TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getParsedExtConfTemplate(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\removeCommentsAndDotsRecursive().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\synchronizeExtConfTemplateWithLocalConfiguration(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions().

◆ getParsedExtConfTemplate()

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::getParsedExtConfTemplate ( string  $extensionKey)

Trigger main ext_conf_template.txt parsing logic. Needs to be public as it is used by install tool ExtensionConfigurationService which adds the comment parsing on top for display of options in install tool.

Parameters
string$extensionKey
Returns
‪array

Definition at line 366 of file ExtensionConfiguration.php.

References TYPO3\CMS\Core\Configuration\ExtensionConfiguration\$setup, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getDefaultConfigurationRawString(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseSub().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots().

◆ parseNextKeySegment()

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::parseNextKeySegment (   $key)
protected

Helper method of ext_conf_template.txt parsing.

Determines the first key segment of a TypoScript key by searching for the first unescaped dot in the given key string.

Since the escape characters are only needed to correctly determine the key segment any escape characters before the first unescaped dot are stripped from the key.

Parameters
string$key‪The key, possibly consisting of multiple key segments separated by unescaped dots
Returns
‪array Array with key segment and remaining part of $key

Definition at line 620 of file ExtensionConfiguration.php.

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\rollParseSub(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\setVal().

◆ parseSub()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::parseSub ( array &  $setup)
protected

◆ removeCommentsAndDotsRecursive()

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::removeCommentsAndDotsRecursive ( array  $config)
protected

Helper method of ext_conf_template.txt parsing.

"Comments" from the "TypoScript" parser below are identified by two (!) dots at the end of array keys and all array keys have a single dot at the end, if they have sub arrays. This is cleaned here.

Incoming array: [ 'automaticInstallation' => '1', 'automaticInstallation..' => '# cat=basic/enabled; ...' 'FE.' => [ 'enabled' = '1', 'enabled..' => '# cat=basic/enabled; ...' ] ]

Output array: [ 'automaticInstallation' => '1', 'FE' => [ 'enabled' => '1', ]

Parameters
array$config‪Incoming configuration
Returns
‪array

Definition at line 433 of file ExtensionConfiguration.php.

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots().

◆ rollParseSub()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::rollParseSub (   $string,
array &  $setup 
)
protected

Helper method of ext_conf_template.txt parsing.

Parsing of TypoScript keys inside a curly brace where the key is composite of at least two keys, thus having to recursively call itself to get the value.

Parameters
string$string‪The object sub-path, eg "thisprop.another_prot"
array$setup‪The local setup array from the function calling this function

Definition at line 557 of file ExtensionConfiguration.php.

References TYPO3\CMS\Core\Configuration\ExtensionConfiguration\$setup, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseNextKeySegment(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseSub().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseSub().

◆ set()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::set ( string  $extension,
string  $path = '',
  $value = null 
)

Store a new or overwrite an existing configuration value.

This is typically used by core internal low level tasks like the install tool but may become handy if an extension needs to update extension configuration on the fly for whatever reason.

Examples: // Set a full extension configuration ($value could be a nested array, too) ->set('myExtension', ['aFeature' => 'true', 'aCustomClass' => 'css-foo'])

// Unset a whole extension configuration ->set('myExtension')

Notes:

  • ‪Do NOT call this at arbitrary places during runtime (eg. NOT in ext_localconf.php or similar). ->set() is not supposed to be called each request since it writes LocalConfiguration each time. This API is however OK to be called from extension manager hooks.
  • ‪Values are not type safe, if the install tool wrote them, boolean true could become string 1 on ->get()
  • ‪It is not possible to store 'null' as value, giving $value=null or no value at all will unset the path
  • ‪Setting a value and calling ->get() afterwards will still return the new value.
  • ‪Warning on AdditionalConfiguration.php: If this file overwrites settings, it spoils the ->set() call and values may not end up as expected.
Parameters
string$extension‪Extension name
string$pathConfiguration path to set - eg. "featureCategory/coolThingIsEnabled"
null$value‪The value. If null, unset the path

Definition at line 188 of file ExtensionConfiguration.php.

References $GLOBALS, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\addDotsToArrayKeysRecursiveForLegacyExtConf(), and TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath().

◆ setAll()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::setAll ( array  $configuration)

Set new configuration of all extensions and reload TYPO3_CONF_VARS. This is a "do all" variant of set() for all extensions that prevents writing and loading LocalConfiguration many times.

Parameters
array$configurationConfiguration of all extensions

Definition at line 231 of file ExtensionConfiguration.php.

References $GLOBALS, and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\addDotsToArrayKeysRecursiveForLegacyExtConf().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions().

◆ setVal()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::setVal (   $string,
array &  $setup,
  $value 
)
protected

Helper method of ext_conf_template.txt parsing.

Setting a value/property of an object string in the setup array.

Parameters
string$string‪The object sub-path, eg "thisprop.another_prot
array$setup‪The local setup array from the function calling this function.
void

Definition at line 581 of file ExtensionConfiguration.php.

References TYPO3\CMS\Core\Configuration\ExtensionConfiguration\$lastComment, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\$setup, and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseNextKeySegment().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseSub().

◆ synchronizeExtConfTemplateWithLocalConfiguration()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::synchronizeExtConfTemplateWithLocalConfiguration ( string  $extensionKey)

Read values from ext_conf_template, verify if they are in LocalConfiguration.php already and if not, add them.

Used public by extension manager when updating extension

Parameters
string$extensionKey‪The extension to sync

Definition at line 288 of file ExtensionConfiguration.php.

References $GLOBALS, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots(), and TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule().

◆ synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions()

TYPO3\CMS\Core\Configuration\ExtensionConfiguration::synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions ( )

If there are new config settings in ext_conf_template of an extension, they are found here and synchronized to LocalConfiguration['EXTENSIONS'].

Used when entering the install tool, during installation and if calling ->get() with an extension or path that is not yet found in LocalConfiguration

Definition at line 256 of file ExtensionConfiguration.php.

References $GLOBALS, TYPO3\CMS\Core\Configuration\ExtensionConfiguration\getExtConfTablesWithoutCommentsAsNestedArrayWithoutDots(), TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\setAll().

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\get().

Member Data Documentation

◆ $commentSet

bool TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$commentSet = false
protected

Internal flag to create a multi-line comment (one of those like /* ... * /) Used parsing ext_conf_template.txt

Definition at line 76 of file ExtensionConfiguration.php.

◆ $inBrace

int TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$inBrace = 0
protected

Internally set, when in brace. Counter. Used parsing ext_conf_template.txt

Definition at line 83 of file ExtensionConfiguration.php.

◆ $lastComment

string TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$lastComment = ''
protected

Holding the value of the last comment Used parsing ext_conf_template.txt

Definition at line 69 of file ExtensionConfiguration.php.

Referenced by TYPO3\CMS\Core\Configuration\ExtensionConfiguration\parseSub(), and TYPO3\CMS\Core\Configuration\ExtensionConfiguration\setVal().

◆ $raw

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$raw
protected

Raw data, the input string exploded by LF. Used parsing ext_conf_template.txt

Definition at line 55 of file ExtensionConfiguration.php.

◆ $rawPointer

int TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$rawPointer = 0
protected

Pointer to entry in raw data array. Used parsing ext_conf_template.txt

Definition at line 62 of file ExtensionConfiguration.php.

◆ $setup

array TYPO3\CMS\Core\Configuration\ExtensionConfiguration::$setup = array( )
protected