ConfigHelper
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\ConfigHelper
- Since
- 3.0.0
Config helper
View source (opens new window)
# Public Methods
Method | Description |
---|---|
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 (opens new window))
- DateInterval object
- an empty value (represents 0 seconds)
View source (opens new window)
Arguments
$value
(mixed
)
Returns
integer (opens new window) – The time duration in seconds
Throws
- yii\base\InvalidConfigException (opens new window)
if the duration can't be determined
# localizedValue()
Returns a localized config setting value.
View source (opens new window)
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 (opens new window), null (opens new window)) – 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 (opens new window) ending in
K
(Kilobytes),M
(Megabytes), orG
(Gigabytes))
View source (opens new window)
Arguments
$value
(integer (opens new window), string (opens new window)) – The size
Returns
integer (opens new window), float (opens new window) – The size in bytes