App
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\App
- Since
- 3.0.0
App helper.
View source (opens new window)
# Public Methods
Method | Description |
---|---|
assetManagerConfig() | Returns the assetManager component config for web requests. |
backtrace() | Returns the backtrace as a string (omitting the final frame where this method was called). |
cacheConfig() | Returns the cache component config. |
checkForValidIconv() | Returns whether the server has a valid version of the iconv extension installed. |
cliOption() | Returns a CLI command option from argv , or null if it wasn’t passed. |
createFormattingLocale() | Creates a locale object that should be used for date and number formatting. |
dbConfig() | Returns the db component config. |
devMode() | Returns whether Dev Mode is enabled. |
editionHandle() | Returns the handle of the given Craft edition. |
editionIdByHandle() | Returns the ID of a Craft edition by its handle. |
editionName() | Returns the name of the given Craft edition. |
editions() | Returns an array of all known Craft editions’ IDs. |
env() | Returns an environment-specific value. |
envConfig() | Returns a config array for a given class, based on any environment variables or PHP constants named based on its public properties. |
extensionVersion() | Returns a PHP extension version, without the distribution info. |
humanizeClass() | Returns a humanized class name. |
isEphemeral() | Returns whether Craft is running on an environment with ephemeral storage. |
isNitro() | Returns whether Craft is running within Nitro (opens new window) v1. |
isPathAllowed() | Returns whether the given path is within PHP’s open_basedir setting. |
isStreamLog() | Returns whether Craft is logging to stdout/stderr. |
isValidEdition() | Returns whether an edition is valid. |
licenseKey() | |
mailSettings() | Returns the system email settings. |
mailerConfig() | Returns the mailer component config. |
maxPowerCaptain() | Sets PHP’s memory limit to the maximum specified by the config4:phpMaxMemoryLimit (opens new window) config setting, and gives the script an unlimited amount of time to execute. |
mutexConfig() | Returns a file-based mutex driver config. |
normalizePhpPaths() | Normalizes a PHP path setting to an array of paths |
normalizeValue() | Normalizes an environment variable/constant name/CLI command option. |
normalizeVersion() | Removes distribution info from a version string, and returns the highest version number found in the remainder. |
parseBooleanEnv() | Checks if a string references an environment variable ($VARIABLE_NAME ) and returns the referenced boolean value, or null if a boolean value can’t be determined. |
parseEnv() | Checks if a string references an environment variable ($VARIABLE_NAME ) and/or an alias (@aliasName ), and returns the referenced value. |
phpConfigValueAsBool() | Retrieves a bool PHP config setting and normalizes it to an actual bool. |
phpConfigValueAsPaths() | Retrieves a file path PHP config setting and normalizes it to an array of paths. |
phpConfigValueInBytes() | Retrieves a disk size PHP config setting and normalizes it into bytes. |
phpExecutable() | Returns the path to a PHP executable which should be used by sub processes. |
phpSizeToBytes() | Normalizes a PHP file size into bytes. |
phpVersion() | Returns the PHP version, without the distribution info. |
projectConfigConfig() | Returns the projectConfig component config. |
sessionConfig() | Returns the session component config for web requests. |
supportsIdn() | Returns whether the server supports IDNA ASCII strings. |
testIniSet() | Tests whether ini_set() works. |
userConfig() | Returns the user component config for web requests. |
viewConfig() | Returns the view component config. |
webRequestConfig() | Returns the request component config for web requests. |
webResponseConfig() | Returns the response component config for web requests. |
# assetManagerConfig()
- Since
- 3.0.18
Returns the assetManager
component config for web requests.
View source (opens new window)
Returns
# backtrace()
- Since
- 3.0.13
Returns the backtrace as a string (omitting the final frame where this method was called).
View source (opens new window)
Arguments
$limit
(integer (opens new window)) – The max number of stack frames to be included (0 means no limit)
Returns
# cacheConfig()
- Since
- 3.0.18
Returns the cache
component config.
View source (opens new window)
Returns
# checkForValidIconv()
Returns whether the server has a valid version of the iconv extension installed.
View source (opens new window)
Returns
# cliOption()
- Since
- 4.0.0
Returns a CLI command option from argv
, or null
if it wasn’t passed.
Supported option syntaxes are:
name=value
name value
name
(impliestrue
)
name
must begin with --
or -
. Other values will be rejected.
If the value is numeric, a float or int will be returned.
If the value is true
or false
, a boolean will be returned.
If the option has no value (either because the following item begins with -
or it’s the last item),
true
will be returned.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The option name, beginning with--
or-
$unset
(boolean (opens new window)) – Whether the option should be removed fromargv
if found
Returns
string (opens new window), float (opens new window), integer (opens new window), true (opens new window), null (opens new window)
# createFormattingLocale()
- Since
- 3.6.0
Creates a locale object that should be used for date and number formatting.
View source (opens new window)
Returns
# dbConfig()
- Since
- 3.0.18
Returns the db
component config.
View source (opens new window)
Arguments
$dbConfig
(craft\config\DbConfig, null (opens new window)) – The database config settings
Returns
# devMode()
- Since
- 4.0.0
Returns whether Dev Mode is enabled.
View source (opens new window)
Returns
# editionHandle()
- Since
- 3.1.0
Returns the handle of the given Craft edition.
View source (opens new window)
Arguments
$edition
(integer (opens new window)) – An edition’s ID.
Returns
string (opens new window) – The edition’s name.
# editionIdByHandle()
- Since
- 3.1.0
Returns the ID of a Craft edition by its handle.
View source (opens new window)
Arguments
$handle
(string (opens new window)) – An edition’s handle
Returns
integer (opens new window) – The edition’s ID
Throws
- yii\base\InvalidArgumentException (opens new window)
if $handle is invalid
# editionName()
Returns the name of the given Craft edition.
View source (opens new window)
Arguments
$edition
(integer (opens new window)) – An edition’s ID.
Returns
string (opens new window) – The edition’s name.
# editions()
Returns an array of all known Craft editions’ IDs.
View source (opens new window)
Returns
array (opens new window) – All the known Craft editions’ IDs.
# env()
- Since
- 3.4.18
Returns an environment-specific value.
Values will be looked for in the following places:
- “Secret” values returned by a PHP file identified by a
CRAFT_SECRETS_PATH
environment variable - Environment variables stored in
$_SERVER
- Environment variables returned by
getenv()
- PHP constants
If the value cannot be found, null
will be returned.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The name to search for.
Returns
mixed
– The value, or null
if not found.
Throws
# envConfig()
- Since
- 4.0.0
Returns a config array for a given class, based on any environment variables or PHP constants named based on its public properties.
Environment variable/PHP constant names must be capitalized, SNAKE_CASED versions of the object’s property names, possibly with a given prefix.
For example, if an object has a fooBar
property, and X
/X_
is passed as the prefix, the resulting array
may contain a fooBar
key set to an X_FOO_BAR
environment variable value, if it exists.
View source (opens new window)
Arguments
$class
(string (opens new window)) – The class name$envPrefix
(string (opens new window), null (opens new window)) – The environment variable name prefix
Returns
# extensionVersion()
Returns a PHP extension version, without the distribution info.
View source (opens new window)
Arguments
$name
(string (opens new window)) – The extension name
Returns
# humanizeClass()
Returns a humanized class name.
View source (opens new window)
Arguments
$class
(string (opens new window))
Returns
# isEphemeral()
- Since
- 3.4.0
Returns whether Craft is running on an environment with ephemeral storage.
View source (opens new window)
Returns
# isNitro()
DEPRECATED
Deprecated in 3.7.9.
- Since
- 3.4.19
Returns whether Craft is running within Nitro (opens new window) v1.
View source (opens new window)
Returns
# isPathAllowed()
- Since
- 3.7.34
Returns whether the given path is within PHP’s open_basedir
setting.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
# isStreamLog()
- Since
- 4.0.0
Returns whether Craft is logging to stdout/stderr.
View source (opens new window)
Returns
# isValidEdition()
Returns whether an edition is valid.
View source (opens new window)
Arguments
$edition
(mixed
) – An edition’s ID (or is it?)
Returns
boolean (opens new window) – Whether $edition is a valid edition ID.
# licenseKey()
View source (opens new window)
Returns
string (opens new window), null (opens new window)
# mailSettings()
- Since
- 3.1.0
Returns the system email settings.
View source (opens new window)
Returns
# mailerConfig()
- Since
- 3.0.18
Returns the mailer
component config.
View source (opens new window)
Arguments
$settings
(craft\models\MailSettings, null (opens new window)) – The system mail settings
Returns
# maxPowerCaptain()
Sets PHP’s memory limit to the maximum specified by the config4:phpMaxMemoryLimit (opens new window) config setting, and gives the script an unlimited amount of time to execute.
View source (opens new window)
# mutexConfig()
- Since
- 3.0.18
Returns a file-based mutex driver config.
TIP
If you were calling this to override the yii\mutex\FileMutex::$isWindows (opens new window) property, note that
overriding the mutex
component may no longer be necessary, as Craft no longer uses a mutex
when Dev Mode is enabled.
View source (opens new window)
Returns
# normalizePhpPaths()
- Since
- 3.7.34
Normalizes a PHP path setting to an array of paths
View source (opens new window)
Arguments
$value
(string (opens new window)) – The PHP path setting value
Returns
string (opens new window)[] – The normalized paths
# normalizeValue()
- Since
- 4.0.0
Normalizes an environment variable/constant name/CLI command option.
It converts the following:
'true'
→true
'false'
→false
- Numeric string → integer or float
View source (opens new window)
Arguments
$value
(mixed
)
Returns
mixed
# normalizeVersion()
Removes distribution info from a version string, and returns the highest version number found in the remainder.
View source (opens new window)
Arguments
$version
(string (opens new window))
Returns
# parseBooleanEnv()
- Since
- 3.7.29
Checks if a string references an environment variable ($VARIABLE_NAME
) and returns the referenced
boolean value, or null
if a boolean value can’t be determined.
View source (opens new window)
Arguments
$value
(mixed
)
Returns
Example
$status = App::parseBooleanEnv('$SYSTEM_STATUS') ?? false;
# parseEnv()
- Since
- 3.7.29
Checks if a string references an environment variable ($VARIABLE_NAME
)
and/or an alias (@aliasName
), and returns the referenced value.
If the string references an environment variable with a value of true
or false
, a boolean value will be returned.
View source (opens new window)
Arguments
Returns
string (opens new window), boolean (opens new window), null (opens new window) – The parsed value, or the original value if it didn’t reference an environment variable and/or alias.
Example
$value1 = App::parseEnv('$SMTP_PASSWORD');
$value2 = App::parseEnv('@webroot');
# phpConfigValueAsBool()
Retrieves a bool PHP config setting and normalizes it to an actual bool.
View source (opens new window)
Arguments
$var
(string (opens new window)) – The PHP config setting to retrieve.
Returns
boolean (opens new window) – Whether it is set to the php.ini equivalent of true
.
# phpConfigValueAsPaths()
- Since
- 3.7.34
Retrieves a file path PHP config setting and normalizes it to an array of paths.
View source (opens new window)
Arguments
$var
(string (opens new window)) – The PHP config setting to retrieve
Returns
string (opens new window)[] – The normalized paths
# phpConfigValueInBytes()
- Since
- 3.0.38
Retrieves a disk size PHP config setting and normalizes it into bytes.
View source (opens new window)
Arguments
$var
(string (opens new window)) – The PHP config setting to retrieve.
Returns
integer (opens new window), float (opens new window) – The value normalized into bytes.
# phpExecutable()
- Since
- 4.5.6
Returns the path to a PHP executable which should be used by sub processes.
View source (opens new window)
Returns
string (opens new window), null (opens new window) – The PHP executable path, or null
if it can’t be determined.
# phpSizeToBytes()
- Since
- 3.6.0
Normalizes a PHP file size into bytes.
View source (opens new window)
Arguments
$value
(string (opens new window)) – The file size expressed in PHP config value notation
Returns
integer (opens new window), float (opens new window) – The value normalized into bytes.
# phpVersion()
Returns the PHP version, without the distribution info.
View source (opens new window)
Returns
# projectConfigConfig()
Returns the projectConfig
component config.
View source (opens new window)
# sessionConfig()
- Since
- 3.0.18
Returns the session
component config for web requests.
View source (opens new window)
Returns
# supportsIdn()
- Since
- 3.7.9
Returns whether the server supports IDNA ASCII strings.
View source (opens new window)
Returns
# testIniSet()
- Since
- 3.0.40
Tests whether ini_set() works.
View source (opens new window)
Returns
# userConfig()
- Since
- 3.0.18
Returns the user
component config for web requests.
View source (opens new window)
Returns
# viewConfig()
- Since
- 3.0.18
Returns the view
component config.
View source (opens new window)
Returns
# webRequestConfig()
- Since
- 3.0.18
Returns the request
component config for web requests.
View source (opens new window)
Returns
# webResponseConfig()
- Since
- 3.3.0
Returns the response
component config for web requests.
View source (opens new window)
Returns
← Api ArrayHelper →