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
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
truestring, and return the converted to a bool type.
|Configuration (string)||Conversion type result|
| ||String (empty string)|
| ||If it is a constant, it is converted to the corresponding value.|