arthem/config-file-bundle 问题修复 & 功能扩展

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

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

arthem/config-file-bundle

Composer 安装命令:

composer require arthem/config-file-bundle

包简介

Inject files from env vars in your Symfony configuration

README 文档

README

Motivations

In Symfony configuration, you can inject file content as parameter using env(file:FOO)

But some Symfony bundles expect you to provide file path whereas your infrastructure can only provide env variables. In some Docker deployments, it is really complicated to mount files and it's easier to deal with env.

This bundle generates files in the cache with your env var written in them, allowing you to write templates.

Let's see a Docker case!

# docker-compose.yaml
services:
  symfony-app:
    environments:
    - JWT_PRIVATE_KEY

The default env var of docker compose can look like:

# .env
JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCN/VTNk1Sdr9mg
...
tDMMHT4ch+pSmyyndMSeu+I+pjF5+cour3FrmmzZFzKivzj0EXbcb+LPUQKBgHWA
WRv4Q33WAa3BFKqCZOKhfFY=
-----END PRIVATE KEY-----
"

You have a jwt_provider bundle that requires a private_key_file (yes, a file path!)

# config/packages/jwt_provider.yaml
    jwt_provider:
        private_key_file: "I don't have file, just a JWT_PRIVATE_KEY env var"

This is where the bundle helps you!

Installation

composer require arthem/config-file-bundle

Usage

Inlined configuration

You can directly write the expected content of your file with the following syntax:

param_value: |
    &file:<filename.ext>
    <content of your file>

example:

# config/packages/jwt_provider.yaml
    jwt_provider:
        private_key_file: |
            &file:jwt_private_key.pem
            %env(JWT_PRIVATE_KEY)%

this will:

  • Generate the file jwt_private_key-%hash%.pem in the project cache directory. (%hash% refers to the resolved content of the file)
  • Compile your configuration into:
# config/packages/jwt_provider.yaml
    jwt_provider:
        private_key_file: 'cache/dir/jwt_private_key-c131d7b5c6bd917a83e0cbea6296bf95.pem'

Provisioned configuration

The other way to generate files is to define them in the bundle extension config:

# config/packages/arthem_config_file.yaml
arthem_config_file:
    files:
        service_account:
            extension: json
            content: |
                {
                  "type": "service_account",
                  "project_id": "my-project",
                  "private_key_id": "%env(json_string:SERVICE_ACCOUNT_ID)%",
                  "private_key": "%env(json_string:SERVICE_ACCOUNT_PRIVATE_KEY)%"
                }
        jwt_private_key:
            extension: pem
            content: '%env(JWT_SECRET_KEY)%'
        jwt_public_key:
            extension: pem
            content: '%env(JWT_PUBLIC_KEY)%'

Then inject files in your configuration:

# config/packages/jwt_provider.yaml
jwt_provider:
    private_key_file: '%arthem_config_file.file.jwt_public_key%'

File content

Escaping values

This bundle also provides its JSON env var processor

{
  "private_key_id": "%env(json_string:SERVICE_ACCOUNT_PRIVATE_KEY)%"
}

This processor escapes JSON strings which can be useful for multiline env vars.

arthem/config-file-bundle 适用场景与选型建议

arthem/config-file-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 992 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 arthem/config-file-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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