承接 earthit/config-loader 相关项目开发

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

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

earthit/config-loader

Composer 安装命令:

composer require earthit/config-loader

包简介

Gives access to structured config values in files or environment variables

README 文档

README

Gives access to structured configuration variables stored in JSON files and/or environment variables.

Example

Let's say config/database.json looks like:

{
	"driver": "postgres",
	"host": "db.example.org",
	"dbname": "OVERRIDE ME PLZ THX",
	"notes": [
		"This is the greatest database configuration.",
		"My brother Bob said so."
	]
}

And we're going to run our PHP script with these environment variables:

database_dbname=bobco
otherthing_json='{"foo":"bar","baz","quux"}'
otherthing_foo="jk actually not bar"

And then we have a script like:

$loader = new EarthIT_ConfigLoader( 'database', $_ENV )
echo "Database: "; var_export($loader->get('database'));
echo "Other thing: "; var_export($loader->get('otherthing'));

Would output something like:

Database: array (
  driver => 'postgres',
  host => 'db.example.org',
  dbname => 'bobco',
  notes => array (
    'This is the greatest database configuration.',
    'My brother Bob said so.'
  )
)
Other thing: array (
  'foo' => 'jk actually not bar',
  'baz' => 'quux'
)

Overrides

Variables are merged in the following order, with later steps 'overriding' the values from earlier steps:

  • JSON files
  • files in subdirectories (e.g. 'foo/bar.json' can override 'bar' from 'foo.json')
  • JSON-encoded environment variables
  • Leaf environment variables

If an array value overrides another array value, they are merged instead of replacing the old one.

Environment variable names

  • Underscores have special meaning, so if you have a variable foo_bar_baz=42, it's going to show up when fetched from the ConfigLoader as array('foo'=>array('bar'=>array('baz'=>42)))

  • The postfix json also has special meaning. It means that the value of the variable named by the part before "_json" will be determined by JSON-decoding this environment variable's value.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固