abstract class ConfigBase implements RefinableCacheableDependencyInterface (View source)

Provides a base class for configuration objects with get/set support.

Encapsulates all capabilities needed for runtime configuration handling for a specific configuration object.

Extend directly from this class for non-storable configuration where the configuration API is desired but storage is not possible; for example, if the data is derived at runtime. For storable configuration, extend \Drupal\Core\Config\StorableConfigBase.

Traits

Provides dependency injection friendly methods for serialization.

Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Constants

MAX_NAME_LENGTH

The maximum length of a configuration object name.

Many filesystems (including HFS, NTFS, and ext4) have a maximum file name length of 255 characters. To ensure that no configuration objects incompatible with this limitation are created, we enforce a maximum name length of 250 characters (leaving 5 characters for the file extension).

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected string $name

The name of the configuration object.

protected array $data

The data of the configuration object.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

string[]
getCacheTags()

The cache tags associated with this object.

string[]
getCacheContexts()

The cache contexts associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

addCacheableDependency($other_object)

{@inheritdoc}

addCacheContexts(array $cache_contexts)

{@inheritdoc}

addCacheTags(array $cache_tags)

{@inheritdoc}

string
getName()

Returns the name of this configuration object.

$this
setName(string $name)

Sets the name of this configuration object.

static 
validateName(string $name)

Validates the configuration object name.

mixed
get(string $key = '')

Gets data from this configuration object.

$this
setData(array $data)

Replaces the data of this configuration object.

$this
set(string $key, mixed $value)

Sets a value in this configuration object.

null
validateKeys(array $data)

Validates all keys in a passed in config array structure.

$this
clear(string $key)

Unsets a value in this configuration object.

$this
merge(array $data_to_merge)

Merges data into a configuration object.

mixed
castSafeStrings(mixed $data)

Casts any objects that implement MarkupInterface to string.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

addCacheableDependency($other_object)

{@inheritdoc}

Parameters

$other_object

addCacheContexts(array $cache_contexts)

{@inheritdoc}

Parameters

array $cache_contexts

addCacheTags(array $cache_tags)

{@inheritdoc}

Parameters

array $cache_tags

mergeCacheMaxAge($max_age)

{@inheritdoc}

Parameters

$max_age

string getName()

Returns the name of this configuration object.

Return Value

string

The name of the configuration object.

$this setName(string $name)

Sets the name of this configuration object.

Parameters

string $name

The name of the configuration object.

Return Value

$this

The configuration object.

static validateName(string $name)

Validates the configuration object name.

Parameters

string $name

The name of the configuration object.

Exceptions

ConfigNameException

See also

Config::MAX_NAME_LENGTH

mixed get(string $key = '')

Gets data from this configuration object.

Parameters

string $key

A string that maps to a key within the configuration data. For instance in the following configuration array: @code array( 'foo' => array( 'bar' => 'baz', ), ); @endcode A key of 'foo.bar' would return the string 'baz'. However, a key of 'foo' would return array('bar' => 'baz'). If no key is specified, then the entire data array is returned.

Return Value

mixed

The data that was requested.

$this setData(array $data)

Replaces the data of this configuration object.

Parameters

array $data

The new configuration data.

Return Value

$this

The configuration object.

Exceptions

ConfigValueException

$this set(string $key, mixed $value)

Sets a value in this configuration object.

Parameters

string $key

Identifier to store value in configuration.

mixed $value

Value to associate with identifier.

Return Value

$this

The configuration object.

Exceptions

ConfigValueException

protected null validateKeys(array $data)

Validates all keys in a passed in config array structure.

Parameters

array $data

Configuration array structure.

Return Value

null

Exceptions

ConfigValueException

$this clear(string $key)

Unsets a value in this configuration object.

Parameters

string $key

Name of the key whose value should be unset.

Return Value

$this

The configuration object.

$this merge(array $data_to_merge)

Merges data into a configuration object.

Parameters

array $data_to_merge

An array containing data to merge.

Return Value

$this

The configuration object.

protected mixed castSafeStrings(mixed $data)

Casts any objects that implement MarkupInterface to string.

Parameters

mixed $data

The configuration data.

Return Value

mixed

The data with any safe strings cast to string.