joe1992w/envsemble 问题修复 & 功能扩展

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

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

joe1992w/envsemble

Composer 安装命令:

composer require joe1992w/envsemble

包简介

A Laravel package for merging multiple .env files with patch support and advanced features.

README 文档

README

Envsemble Logo

A powerful Laravel package for merging multiple .env files with patch support and advanced features.

Envsemble allows you to maintain a base environment configuration and apply targeted patches for different environments, features, or deployment scenarios. Perfect for managing complex Laravel applications with multiple deployment targets.

✨ Features

  • 🔧 Base + Patch Architecture: Start with a base .env file and apply patches
  • 🗑️ Key Deletion: Use KEY=__DELETE__ to remove keys during merge
  • 📝 Source Tracking: Each line in the output shows which file it came from
  • 🔍 Dry Run Mode: Preview changes before applying them
  • 📊 Detailed Reports: See what was added, modified, or deleted
  • 🗜️ Squash Mode: Combine all files into a new base and remove patches
  • 🎯 CLI Integration: Full Laravel Artisan command support
  • Comprehensive Tests: Full PHPUnit/Pest test coverage

📦 Installation

Install via Composer:

composer require joe1992w/envsemble

For Laravel applications, the service provider will be auto-discovered. For manual registration:

// config/app.php
'providers' => [
    // ...
    JoeWare\Envsemble\EnvsembleServiceProvider::class,
],

🚀 Quick Start

1. Basic Usage

php artisan env:build --base=.env.base --patches=env-patches/ --out=.env.generated

2. Dry Run (Preview Changes)

php artisan env:build --base=.env.base --patches=env-patches/ --out=.env.generated --dry-run

3. Squash Mode (Combine All Files)

php artisan env:build --base=.env.base --patches=env-patches/ --out=.env.new --squash

📁 File Structure Example

project/
├── .env.base                 # Base environment file
├── env-patches/              # Directory containing patch files
│   ├── 01-development.env    # Development overrides
│   ├── 02-local-testing.env  # Testing configuration
│   └── 03-mail-debug.env     # Mail debugging settings
└── .env.generated            # Final merged output

📝 Syntax Examples

Base File (.env.base)

APP_NAME="My Laravel App"
APP_ENV=production
APP_DEBUG=false
DB_HOST=127.0.0.1
DB_DATABASE=production_db
CACHE_DRIVER=redis
MAIL_MAILER=smtp

Patch File (01-development.env)

# Override for development
APP_ENV=local
APP_DEBUG=true

# Add new keys
LOG_LEVEL=debug
TELESCOPE_ENABLED=true

# Delete keys (removes from final output)
CACHE_DRIVER=__DELETE__

Generated Output (.env.generated)

# Generated by Envsemble on 2025-06-03 10:30:00
# Base: .env.base
# Patches: 01-development.env

APP_NAME="My Laravel App" # from: .env.base
APP_ENV=local # from: 01-development.env
APP_DEBUG=true # from: 01-development.env
DB_HOST=127.0.0.1 # from: .env.base
DB_DATABASE=production_db # from: .env.base
MAIL_MAILER=smtp # from: .env.base
LOG_LEVEL=debug # from: 01-development.env
TELESCOPE_ENABLED=true # from: 01-development.env

🛠️ Command Options

Option Description Required
--base Path to the base .env file
--patches Directory containing patch files
--out Output file path
--dry-run Preview changes without writing files
--no-comments Exclude source comments from output
--squash Combine all files and remove patches

📊 Merge Reports

After each merge, Envsemble provides a detailed report:

📊 Merge Report:
┌─────────────────────┬───────┐
│ Metric              │ Count │
├─────────────────────┼───────┤
│ Base file keys      │ 15    │
│ Patch files processed│ 3     │
│ Keys added          │ 4     │
│ Keys modified       │ 3     │
│ Keys deleted        │ 2     │
│ Final output keys   │ 20    │
└─────────────────────┴───────┘

➕ Added keys: LOG_LEVEL, TELESCOPE_ENABLED, DEBUGBAR_ENABLED, API_KEY
🔄 Modified keys: APP_ENV, APP_DEBUG, MAIL_MAILER
🗑️  Deleted keys: REDIS_HOST, CACHE_DRIVER

📁 Files processed:
   Base: .env.base
   Patch: 01-development.env
   Patch: 02-testing.env
   Patch: 03-debug.env

📈 Efficiency: 133.3% keys retained/added from base

🔧 Programmatic Usage

You can also use Envsemble programmatically:

use JoeWare\Envsemble\EnvMerger;

$merger = new EnvMerger();

// Basic merge
$result = $merger->merge('.env.base', 'env-patches/');
$output = $merger->generateOutput($result);
file_put_contents('.env.generated', $output);

// Get detailed report
$report = $result->getReport();
echo "Added {$result->getAddedKeysCount()} keys\n";
echo "Modified {$result->getModifiedKeysCount()} keys\n";

// Squash files
$result = $merger->squash('.env.base', 'env-patches/', '.env.new');

🏗️ Advanced Use Cases

Environment-Specific Builds

# Development
php artisan env:build --base=.env.base --patches=patches/dev/ --out=.env

# Staging  
php artisan env:build --base=.env.base --patches=patches/staging/ --out=.env

# Production
php artisan env:build --base=.env.base --patches=patches/prod/ --out=.env

Feature Flag Management

# Enable feature flags
php artisan env:build --base=.env.base --patches=features/feature-x/ --out=.env

# Disable feature (using __DELETE__ in patch)
php artisan env:build --base=.env.base --patches=features/disable-feature-x/ --out=.env

CI/CD Integration

# GitHub Actions example
- name: Build Environment
  run: |
    php artisan env:build \
      --base=.env.production \
      --patches=deploy/patches/ \
      --out=.env \
      --no-comments

🧪 Testing

Run the test suite:

composer test

Individual test commands:

composer test:unit      # Unit tests
composer test:types     # Static analysis
composer test:lint      # Code style

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

📄 License

This package is open-sourced software licensed under the MIT license.

🙋‍♂️ Support

Made with ❤️ by Joe Ware

joe1992w/envsemble 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-03