承接 rb-cohen/php-env 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rb-cohen/php-env

最新稳定版本:1.1.0

Composer 安装命令:

composer require rb-cohen/php-env

包简介

Envrionment variable helper

README 文档

README

Useful function for getting envrionment varibles for config, with a default fallback if the variable is not set.

Functions

env($name, $default = null)

Looks for an environment variable called $name, returning $default if the variable is not available.

$default can be an anonymous function, which will be called to obtain a value if the environment variable is not set.

Strings 'true', 'false' and 'null' will be converted to their PHP types true, false and null.

env_to_array($name, $default = array())

Similar to env, calls env internally, but will split the env variable or default value in to an array by comma.

Also trims the array values.

resolve_value($value)

Used by env() to recursively call anonymous functions to resolve a value if the variable is not set.

Examples

Basic config

$config = [
  'mysql' => [
    'host' => env('DB_HOST', 'localhost'),
    'username' => env('DB_USERNAME', 'dbuser'),
    'password' => env('DB_PASSWORD'),
    'dbname' => env('DB_NAME', 'my_database'),
  ]
];

Using an anonymous function

$username = env('USER', function(){
  return exec('whoami');
});

统计信息

  • 总下载量: 2.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-06