定制 24hoursmedia/php-env-inject 二次开发

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

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

24hoursmedia/php-env-inject

Composer 安装命令:

composer require 24hoursmedia/php-env-inject

包简介

Inject and interpolate environment variables into strings. Supports substituting default values for an env var, and escapers/formatters using callbacks. Partially supports POSIX compliant shell syntax.

README 文档

README

Inject/interpolate environment variables in strings.

  • Substitutes raw environment variables in strings
  • Supports default values if environment variable is not set
  • Supports escaping JSON strings
  • Supports a callback to write your own value modifiers / escapers

Security Considerations

⚠️ As often environment variables on a system may contain sensitive data, especially if you use dotenv, you should NEVER ALLOW USER INPUT into the interpolator.

⚠️ Only interpolate into strings that are under your control and fully trusted!

Install

composer require 24hoursmedia/php-env-inject

Usage

Interpolate env vars in a string

<?php
use T4\EnvInject\EnvInject;
putenv('YOUR_NAME=John Doe');

echo EnvInject::interpolate('Hello ${YOUR_NAME}! ${MESSAGE:-Have a nice day!}');
// Hello John Doe! Have a nice day!

Interpolation in JSON strings

Escape json values with JsonEnvInject::interpolate():

Substituting raw environment variables in JSON strings can result in failures if you have special characters in your values such as quotes. The JsonEnvInject class can escape JSON strings for you before interpolation.

<?php
use T4\EnvInject\JsonEnvInject;
putenv('FOO=f"o"o');
echo JsonEnvInject::interpolate('{"foo":"${FOO}"}');
// {"foo":"f\"o\"o"}

Modify values with a callback function

Use EnvInject::interpolateWithCallback(string $string, Closure $callback) to modify values with a callback function.

The callback function receives the value as first argument and the key as second argument. It should return the modified value to interpolate.

Use this to create your own escape functions or more complex modifiers.

Develop and run tests

Open project in a docker container:

docker run -it --rm -v $(pwd):/app -w /app php:8.0-cli-alpine /bin/sh
apk add php-curl php-mbstring php-openssl php-zip php-phar
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
composer install

# run tests
./vendor/bin/phpunit tests --testdox

24hoursmedia/php-env-inject 适用场景与选型建议

24hoursmedia/php-env-inject 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 24hoursmedia/php-env-inject 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 24hoursmedia/php-env-inject 我们能提供哪些服务?
定制开发 / 二次开发

基于 24hoursmedia/php-env-inject 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-11-03