ndobromirov/php-env-dereference 问题修复 & 功能扩展

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

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

ndobromirov/php-env-dereference

Composer 安装命令:

composer require ndobromirov/php-env-dereference

包简介

PHP environment variables dereference library.

README 文档

README

Allow dereferencing of environment variables in PHP.

Overview

This is generally useful, in cloud environments, where different backing services are injected into PHP with some strange names. At that point the developer is either using that strange names in his code or starting to do workarounds.

This particular library solves this based on the idea from variable dereference feature that is already in PHP engine.

<?php
$a = 'hello';
$$a = 'world';
// Same output.
echo "$a ${$a}\n", "hello world\n";

This is very similar to the phpdotenv nested variables functionality, but exposing only it with a simpler syntax and allowing recursive dereferencing.

Library examples

// We have this environment variables.
putenv('MY_VAR_1=1');
putenv('MY_VAR_2=#MY_VAR_1');
putenv('MY_VAR_3=#MY_VAR_2');
putenv('MY_VAR_4=#MY_VAR_2 #MY_VAR_3');

// Simple dereferencing
echo EnvDereference\Variable::get('MY_VAR_3'); // Should output '#MY_VAR_1'.
echo EnvDereference\Variable::getRecursive('MY_VAR_3'); // Should output '1'.

// Multiple dereferencing
echo EnvDereference\Variable::getEmbedded('MY_VAR_4'); // Should output '#MY_VAR_1 #MY_VAR_2'.
echo EnvDereference\Variable::getEmbeddedRecursive('MY_VAR_4'); // Should output '1 1'.

// Provide defaultds for missing variables
echo EnvDereference\Variable::get('MY_MISSING_VAR', 'default'); // Should output 'default'.

Install

composer require ndobromirov/php-env-dereference

Contribute.

The library complies with PSR-2. Validate with composer cs.
The run tests with composer test.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固