Environmental configuration

Configuration method

File configuration

The project root directory is configured with a .env file and configured in KV format. The data configured by this file can be loaded into the memory for business use.

 APP_DEBUG = 1
SWOFT_DEBUG = 1 

System variable

In addition to file mode configuration, some parameters can be configured to system variables, and system variable parameters are also loaded into memory for business use.

how to use

Swoft provides functions to read the data configured in the above two ways.

 env(string $key = null, mixed $default = null): mixed 

Get the value of an environment variable or all environment variable parameters

  • Returns the value of the environment variable key, or the default value if the environment variable key does not exist. If the key argument is omitted, all environment variables will be returned as an associative array array
  • Default default value, can be any type, can also be a closure
  • The return value is converted by default. For example, configure a true string, and return the converted to a bool type.

Special rules

Configuration (string) Conversion type result
true / false / (true) / (false) Bool
empty String (empty string)
null Null
A_B If it is a constant, it is converted to the corresponding value.
/docs/2.x/en/config/env.html
progress-bar