定制 brannow/envyml 二次开发

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

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

brannow/envyml

Composer 安装命令:

composer require brannow/envyml

包简介

Registers environment variables from a env.yml file

README 文档

README

symfony/dotenv adapter to load env.yml file instead

the env file will be cached with the symfony filecache adaper (the modified time of the env.yml will be check every request, updates will immediately invalidate the cache)

the yaml syntax will be reformed to match the flat Environment structure. nested element keys will be concated via ' _ ' (underscore). (numeric lists are KEY_0, KEY_1)

for example:

Vendor:
  SSO:
    Secret: superSecret
    Provider: stuff
  Captcha:
    secret: otherSecret
    Domain: http://oldDomain
    
Vendor_Captcha:
  Domain: https://domain

will be result in system env:

Vendor_SSO_Secret = superSecret
Vendor_SSO_Provider = stuff
Vendor_Captcha_Secret = otherSecret
Vendor_Captcha_Domain = https://domain

Installation

composer: composer require brannow/envyml

Post Integration

Disclamer: all code shown is based on symfony 5.0 (other symfony versions may need updates to run)

it is required to remove the dotenv code snippets from the index.php and bin/console

// ...

// env.yml loader announcement, this will disable dotenv loader
$_SERVER['APP_RUNTIME'] = \Brannow\Component\Envyml\SymfonyRuntime::class;

// set the custom APP_RUNTIME before this line!
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

// ...

update the path to your env.yml location:

putenv(ENV_FILE_PATH, 'ABSOLUTE_PATH_HERE')

or change in the entrypoint scripts (index.php / console)

// env.yml loader announcement, this will disable dotenv loader
$_SERVER['APP_RUNTIME'] = \Brannow\Component\Envyml\SymfonyRuntime::class;
$_ENV['ENV_FILE_PATH'] ??= './env.yml';

// symfony default
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

Best Practice

next update index.php and bin/console
index.php:

<?php

use App\Kernel;

// env.yml loader announcement, this will disable dotenv loader
$_SERVER['APP_RUNTIME'] = \Brannow\Component\Envyml\SymfonyRuntime::class;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
    return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

bin/console:

#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
    throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

// env.yml loader announcement, this will disable dotenv loader
$_SERVER['APP_RUNTIME'] = \Brannow\Component\Envyml\SymfonyRuntime::class;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
    $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

    return new Application($kernel);
};

simply add

$_SERVER['APP_RUNTIME'] = \Brannow\Component\Envyml\SymfonyRuntime::class;

before

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

brannow/envyml 适用场景与选型建议

brannow/envyml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.83k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「yaml」 「environment」 「env」 「dotenv」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 brannow/envyml 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-13