oscarotero/env
最新稳定版本:v2.1.1
Composer 安装命令:
composer require oscarotero/env
包简介
Simple library to consume environment variables
关键字:
README 文档
README
Simple library to get environment variables converted to simple types.
Installation
This package is installable and autoloadable via Composer as oscarotero/env.
composer require oscarotero/env
Example
use Env\Env; // Using getenv function: var_dump(getenv('FOO')); //string(5) "false" // Using Env: var_dump(Env::get('FOO')); //bool(false)
Available conversions
"false"is converted to booleanfalse"true"is converted to booleantrue"null"is converted tonull- If the string contains only numbers is converted to an integer
- If the string has quotes, remove them
Options
To configure the conversion, you can use the following constants (all enabled by default):
Env::CONVERT_BOOLTo convert boolean valuesEnv::CONVERT_NULLTo convert null valuesEnv::CONVERT_INTTo convert integer valuesEnv::STRIP_QUOTESTo remove the quotes of the strings
There's also additional settings that you can enable (they're disabled by default)
Env::USE_ENV_ARRAYTo get the values from$_ENV, insteadgetenv().Env::USE_SERVER_ARRAYTo get the values from$_SERVER, insteadgetenv().Env::LOCAL_FIRSTTo get first the values of locally-set environment variables.
use Env\Env; //Convert booleans and null, but not integers or strip quotes Env::$options = Env::CONVERT_BOOL | Env::CONVERT_NULL; //Add one more option Env::$options |= Env::USE_ENV_ARRAY; //Remove one option Env::$options ^= Env::CONVERT_NULL;
Default value
By default, if the value does not exist, returns null, but you can change for
any other value:
use Env\Env; Env::$default = false;
The env() function
You can use the env() function, like in Laravel or other frameworks:
use function Env\env; var_dump(env('FOO'));
Please see CHANGELOG for more information about recent changes.
The MIT License (MIT). Please see LICENSE for more information.
统计信息
- 总下载量: 10.87M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 94
- 点击次数: 1
- 依赖项目数: 171
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04