Skip to content
axios edited this page Oct 8, 2020 · 9 revisions

Get details from the \tpr\Env code.

Load the .env file in the project's root directory at application startup. Other custom env files are loaded by the \tpr\Env::load method.

Load env data

\tpr\Env::load($relative_path);

$relative_path is the path relative to the root path of the project.

for example : \tpr\Env::load('.env.production'); // will load {project_root}/.env_production file

Get env data

will get from environment variables if not configured in any env files.

\tpr\Env::get($key = null, $default = null);

returns the default value if it is not configured in either the environment variable or any env file.

Configuration

  • configured on env file

The structure of the .env file is the same as the ini file.

[test]
foo="bar"
$env = \tpr\Env::get("test.foo");
// the $env is "bar"
  • configured on environment variables
export TEST_ENV_KEY_NAME="env value"
$env = \tpr\Env::get("test.env.key.name");
// the $env is "env value"
Clone this wiki locally