定制 flavioheleno/env 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 $default value 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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2019-09-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固