PHPackages                             joe1992w/envsemble - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. joe1992w/envsemble

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

joe1992w/envsemble
==================

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

v0.1.0(11mo ago)00MITPHPPHP ^8.2.0CI failing

Since Jun 3Pushed 11mo agoCompare

[ Source](https://github.com/Joe1992w/envsemble)[ Packagist](https://packagist.org/packages/joe1992w/envsemble)[ RSS](/packages/joe1992w-envsemble/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

Envsemble
=========

[](#envsemble)

 [![Envsemble Logo](docs/images/logo.png)](docs/images/logo.png)

**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
----------

[](#-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
--------------

[](#-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
-------------

[](#-quick-start)

### 1. Basic Usage

[](#1-basic-usage)

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

### 2. Dry Run (Preview Changes)

[](#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)

[](#3-squash-mode-combine-all-files)

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

📁 File Structure Example
------------------------

[](#-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
-----------------

[](#-syntax-examples)

### Base File (.env.base)

[](#base-file-envbase)

```
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)

[](#patch-file-01-developmentenv)

```
# 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-output-envgenerated)

```
# 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
------------------

[](#️-command-options)

OptionDescriptionRequired`--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
---------------

[](#-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
--------------------

[](#-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
---------------------

[](#️-advanced-use-cases)

### Environment-Specific Builds

[](#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

[](#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

[](#cicd-integration)

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

🧪 Testing
---------

[](#-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
--------------

[](#-contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

🙋‍♂️ Support
------------

[](#‍️-support)

- **Issues**: [GitHub Issues](https://github.com/joe1992w/envsemble/issues)
- **Discussions**: [GitHub Discussions](https://github.com/joe1992w/envsemble/discussions)

---

**Made with ❤️ by [Joe Ware](https://joeware.io)**

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance51

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

349d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0efb7b600c2448aa14cb6de24060dd22163aaab8a89aa6e2dbe4b92ea256888f?d=identicon)[joe1992w](/maintainers/joe1992w)

---

Top Contributors

[![Joe1992w](https://avatars.githubusercontent.com/u/2895165?v=4)](https://github.com/Joe1992w "Joe1992w (3 commits)")

---

Tags

phplaravelpackageenvironmentenvmergepatch

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joe1992w-envsemble/health.svg)

```
[![Health](https://phpackages.com/badges/joe1992w-envsemble/health.svg)](https://phpackages.com/packages/joe1992w-envsemble)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
