Skip to content

ConfigHelper ​

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\ConfigHelper
Since
3.0.0

Config helper

View source

Public Methods ​

MethodDescription
durationInSeconds()Normalizes a time duration value into the number of seconds it represents.
localizedValue()Returns a localized config setting value.
sizeInBytes()Normalizes a file size value into the number of bytes it represents.

durationInSeconds() ​

Normalizes a time duration value into the number of seconds it represents.

Accepted formats:

  • integer (the duration in seconds)
  • string (a duration interval)
  • DateInterval object
  • an empty value (represents 0 seconds)

View source

Arguments ​

  • $value (mixed)

Returns ​

integer – The time duration in seconds

Throws ​

localizedValue() ​

Returns a localized config setting value.

View source

Arguments ​

  • $value (mixed) – The config setting value. This can be specified in one of the following forms:
  • A scalar value or null: represents the desired value directly, and will be returned verbatim.
  • An associative array: represents the desired values across all sites, indexed by site handles. If a matching site handle isn’t listed, the first value will be returned.
  • A PHP callable: either an anonymous function or an array representing a class method ([$class or $object, $method]). The callable will be passed the site handle if known, and should return the desired config value.
  • $siteHandle (string, null) – The site handle the value should be defined for. Defaults to the current site.

Returns ​

mixed

sizeInBytes() ​

Normalizes a file size value into the number of bytes it represents.

Accepted formats;

  • integer (the size in bytes)
  • string (a shorthand byte value ending in K (Kilobytes), M (Megabytes), or G (Gigabytes))

View source

Arguments ​

Returns ​

integer, float – The size in bytes