flavioheleno/env
Composer 安装命令:
composer require flavioheleno/env
包简介
Handle environment variables like a breeze.
README 文档
README
Handle environment variables like a breeze.
Install with composer
composer require flavioheleno/env
Read or Required?
This library comes with two helpers:
Env\Read, which will try to read a variable and return its value or fallback to the$defaultvalue when the variable isn't set;Env\Required, which will try to read a variable and return its value or throw an exception when the variable isn't set.
Usage
You can read environment variables with:
$value = Env\Read::asString('my_var', 'default_value');
On the other hand, you can require environment variables with:
try { $value = Env\Required::asString('my_var'); } catch (RuntimeException $exception) { // handle exception }
Immutable environment
The library loads the environment variables into a internal copy on the first method call.
If you ever need to update the internal copy, you can do that with:
Env\Read::updateEnv();
or:
Env\Required::updateEnv();
Available methods
All methods below are available in both the Env\Read and Env\Required helpers.
- updateEnv: Updates the internal env var copy;
- asString:: Returns the value as a string;
- asArray: Returns the values as an array (comma separated);
- asInteger: Returns the value as an integer;
- asFloat: Returns the value as a float;
- asBool: Returns the value as a boolean;
- fromJson: Returns the value as a json decoded value/object;
- fromSerialized: Returns the value as a unserialized value/object.
Contributing
There are a few helper scripts that can be called by composer, such as:
- Static Code Analysis:
php composer.phar run check - Code Linting:
php composer.phar run lint - Tests:
php composer.phar run test
NOTE: to run the Code Linting, you must download the ruleset from here first.
License
This library is licensed under the MIT License.
统计信息
- 总下载量: 118
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2019-09-18