定制 nixiware/config 二次开发

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

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

nixiware/config

Composer 安装命令:

composer require nixiware/config

包简介

Configuration helper for containerized applications

README 文档

README

Introduction

When running PHP applications using orchestration systems (like Docker Swarm / Kubernetes) a lot of configuration is done using environment variables.

While PHP comes with getenv() for reading environmnet variables, a lot of time it proves limited when dealing with secrets (reading values from files) or explicitly casting the values to a certain type.

Requirements

  • PHP 5.3

Usage

  1. Import package namespace use Nixiware\Config\EnvVar;
  2. Import environment variables using the static method get($name, $required, $default, $explicitCastType)
  • $name - name of the environmnet variable
  • $required - sets the variable as required / optional for the execution
  • $default - default value to return if environment variable is not set
  • $explicitCastType - explicitly cast the returned value to a type

EnvVar will first look for an environment variable with the suffix _FILE, and if a file path is specified, it will load the contents of that file.

If a variable is specified as required and no default value is provided, a Nixiware\Config\Exception will be thrown.

Examples

  • Reading a variable named DB_HOST, set as not required with a default value of 127.0.0.1
EnvVar::get('DB_HOST', false, '127.0.0.1');
  • Reading a variable named REST_API_ENABLED, set as required with no default value, and casted as a boolean.
EnvVar::get('REST_API_ENABLED', true, null, EnvVar::TypeBool);
  • Reading a variable from a file, named DB_PASSWORD, set as required with no default value.
EnvVar::get('DB_PASSWORD', true);

Path for the file will be specified using the environment variable DB_PASSWORD_FILE. The variable with the suffix _FILE is automatically read to allow more flexibility in configuring your application, without requiring to modify the actual configuration files.

Testing

Giving the fact that the package is designed to help with Docker / Kubernetes deployments, the unit tests must be ran inside a Docker container.

  1. Open docker/ directory and run bash deployment-start.sh to start the container
  2. Connect to container (similar to SSH) by running bash container-ssh.sh
  3. Run the install script bash install.sh (inside the container)
  4. Run the tests script bash run-tests.sh (inside the container)

For cleanup simply run bash deployment-stop.sh after exiting the container.

License

Config is available under the MIT license. See the LICENSE file for more info.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固