opxcore/config-environment 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

opxcore/config-environment

Composer 安装命令:

composer require opxcore/config-environment

包简介

The OpxCore config environment loader.

关键字:

README 文档

README

Build Status Coverage Status Latest Stable Version Total Downloads License

Installing

composer require opxcore/config-environment

Important notice

All environment variables are stored in static property so any instance of environment would have access to the same set of environment variables.

Usage

use OpxCore\Config\Environment;

$environment = new Environment($path);

where $path is directory where environment file is placed.

Loading environment

To load environment variables from file call $environment->load($filename), where $filename is a name of file. All variables would be stored locally, not affecting any of $_ENV, $_SERVER and so on.

Additional arguments is load($filename, $safe, $silent). If $safe is set to true variables would not be overwritten if they are already present. If $silent is set to true no exceptions would be thrown. Function returns true if environment file wss processed successfully, false in case of any errors.

Reading environment variables

$environment->get($key, $default) returns environment variable if it set, otherwise returns value assigned to default or return value of callable passed to as default.

$environment->has($key) returns true is environment variable set, false otherwise.

Manipulations

$environment->set($key, $value, $safe) sets value to environment. If $safe is set to true variables would not be overwritten if they are already present. Passed values of string type it would be parsed (see below), others would be set as is.

$environment->unset($key) removes variable from environment.

Format

Each line of environment must contain one value, consisting of variable name and its value separated by = sign. Other words, part of line before = sign would be used as variable name, another part would be value of variable.

For example:

APP_NAME=My awesome application

Each value would be parsed according next rules:

String

Each quoted value would be converted to unquoted strings.

DB_CONNECTION="mysql"
DB_HOST="127.0.0.1"

Result of $environment->get('DB_HOST') would be '127.0.0.1'.

Boolean

If value is true or false it would be converted to boolean type.

CACHE_ENABLE=true
304_RESPONSE=false

Null

Null values would set to null

CACHE_DRIVER=null

Array

Arrays must start with [ and ends with ]. Items must be separated by commas. Each item would be parsed according this rules. Nested arrays are not supported.

BROADCAST_DRIVER=[log,telegram]

Numbers

If value represents any of number format it would be converted to integer or float.

COUNT=42
MULTIPLIER=1.05
FLOAT=0.15E-10

If parser would not recognise type of value, original string would be returned.

APP_KEY=base64:0vqkPYSbwPm3MOzdxQJ76Ps6pouZRjN5xPx3b+dm628=

Result of $environment->get('APP_KEY') would be 'base64:0vqkPYSbwPm3MOzdxQJ76Ps6pouZRjN5xPx3b+dm628='.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固