定制 bckp/environment-adapter 二次开发

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

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

bckp/environment-adapter

最新稳定版本:v1.0.0

Composer 安装命令:

composer require bckp/environment-adapter

包简介

Simple class for getting environment in proper type with fallback

README 文档

README

Bckp/Environment-adapter

Adapter for Nette so you can use *.env config files.

Coverage Status Build Status Downloads this Month Scrutinizer Code Quality Latest stable License

Installation

The best way to install Bckp/Environment-adapter is using Composer:

$ composer require bckp/environment-adapter

Development

This package is currently maintaining by these authors.

How to use

For use this adapter, you need to use Bckp/Configurator instead of Nette one. It will autoregister ENV extension support. After that, you can simply link some-name.env file and nette will inject env variables into %env%. The expected syntax is name_of_env_variable: ::{string|int|float|bool}(default: {string}, hidden: {true|false}) name_of_array_variable: ::array(separator: {string}, hidden: {true|false}, cast: {int|float|bool|string})

first entry is name of ENV variable, this will add %env.name_of_env_variable% to the parameters and get value using getenv('NAME_OF_ENV_VARIABLE'); next is :: that will tell adapter, we are working with entity, this is just shortcut to force nette get arguments using internal mechanism. after that, we have cast part, this tells adapter, what type of variable he should cast to, usefull as env know only strings, with this, you can have INTs, FLOATs, BOOLs and even ARRAY of INT, FLOAT, STRING, BOOL.

attributes inside

default: that is fallback, if no value is found using getenv.
hidden: if variable must remain secret, or we can burn it into generated container file (if we have password, we do not want to have it stored in PHP file, but kept it in ENV only)
cast: only for Array, cast values to specific type
separator: only for Array, used for explode

if you keep order of arguments same as Environment class expect, you can omit their names.

Example file

service_user: ::string(secret_user)
service_password: ::string(secret_password, true)
service_port: ::int(1234)
service_nonstring: ::nonstring(1234)
service_active: ::bool(\'false\')
service_array: ::array(cast: int)

with .env

SERVICE_USER=someuser
SERVICE_PASSWORD=supersecret
SERVICE_ARRAY=1|2|3|4

will be translated to if none ENV

[
	'service_user' => 'someuser',
	'service_password' => Bckp\Environment::string('SERVICE_PASSWORD', 'secret_password'),
	'service_port' => 1234,
	'service_nonstring' => '1234',
	'service_active' => false # notice string false is translated to the boolean correctly
	'service_array' => [1,2,3,4],
]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-04