PHPackages                             tourze/env-manage-bundle - 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. tourze/env-manage-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/env-manage-bundle
========================

Symfony环境变量管理束，支持数据库存储和动态加载环境变量配置

0.3.0(4mo ago)04041MITPHPCI passing

Since Apr 19Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/env-manage-bundle)[ Packagist](https://packagist.org/packages/tourze/env-manage-bundle)[ RSS](/packages/tourze-env-manage-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (48)Versions (14)Used By (1)

Env Manage Bundle
=================

[](#env-manage-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/ae848ced826e3e236d831c8c889143ec70a4140cdb85c9329ca45bebde99ba36/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f656e762d6d616e6167652d62756e646c652e737667)](https://packagist.org/packages/tourze/env-manage-bundle)[![Total Downloads](https://camo.githubusercontent.com/e443c5e8e41440ca633867065db31cebccbd87a74c8a135e541480a4fa374a8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f656e762d6d616e6167652d62756e646c652e737667)](https://packagist.org/packages/tourze/env-manage-bundle)
[![PHP Version](https://camo.githubusercontent.com/8f1009c8920c78f2551a783718ea1e66c61161766c122cb271d8e7604661c860/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f656e762d6d616e6167652d62756e646c652e737667)](https://packagist.org/packages/tourze/env-manage-bundle)[![License](https://camo.githubusercontent.com/debb0674d664877176892d3e6a2f3b4639435081d15f7accac7da2fd12130450/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f656e762d6d616e6167652d62756e646c652e737667)](https://packagist.org/packages/tourze/env-manage-bundle)
[![Build Status](https://camo.githubusercontent.com/07c5a0015c097e0dfbb44d4220df0eed6a623d83eceb02ac299fe96b8e4e1a73/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d6173746572)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/9cb168340a6d5a1bdda8e16dafe8eed3d60f1441986fb63de17bff84ee6a18f0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f)](https://codecov.io/gh/tourze/php-monorepo)

A Symfony bundle for managing environment variables in the database, supporting runtime loading, synchronization, and auditing.

This bundle provides a secure and flexible way to manage application configuration through database-stored environment variables, with automatic loading for HTTP requests, CLI commands, and message workers.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
    - [Install via Composer](#install-via-composer)
    - [Enable the Bundle](#enable-the-bundle)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
    - [Security Configuration](#security-configuration)
    - [Admin Interface](#admin-interface)
    - [Caching](#caching)
- [Events and Extension Points](#events-and-extension-points)
- [Advanced Usage](#advanced-usage)
- [Documentation](#documentation)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)
- [Changelog](#changelog)

---

Features
--------

[](#features)

- **Database-driven Configuration**: Store and manage environment variables in the database
- **Runtime Loading**: Automatically load variables for HTTP requests, CLI commands, and message workers
- **Security First**: Built-in protection against dangerous environment variables (LD\_PRELOAD, APP\_\*, etc.)
- **Full Audit Trail**: Track all changes with Snowflake IDs, user, IP, and timestamps
- **Fine-grained Control**: Enable/disable individual variables, add remarks, control synchronization
- **Cache Layer**: High-performance caching with automatic invalidation on changes
- **Admin Interface**: Ready-to-use EasyAdmin CRUD controller for management
- **JSON-RPC Support**: Built-in procedure for fetching public configuration
- **Twig Integration**: Access environment variables directly in templates

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- Doctrine ORM &gt;= 2.20

Installation
------------

[](#installation)

### Install via Composer

[](#install-via-composer)

```
composer require tourze/env-manage-bundle
```

### Enable the Bundle

[](#enable-the-bundle)

Usually auto-registered via Symfony Flex. If not, add to `config/bundles.php`:

```
Tourze\EnvManageBundle\EnvManageBundle::class => ['all' => true],
```

Quick Start
-----------

[](#quick-start)

### 1. Create the Database Table

[](#1-create-the-database-table)

```
# Generate migration
php bin/console make:migration

# Run migration to create base_env table
php bin/console doctrine:migrations:migrate
```

2. Add Environment Variables
----------------------------

[](#2-add-environment-variables)

```
use Tourze\EnvManageBundle\Entity\Env;
use Doctrine\ORM\EntityManagerInterface;

$env = new Env();
$env->setName('API_ENDPOINT');
$env->setValue('https://api.example.com');
$env->setValid(true);
$env->setSync(false);
$env->setRemark('External API endpoint');

$entityManager->persist($env);
$entityManager->flush();
```

3. Access Variables
-------------------

[](#3-access-variables)

```
// In services
$apiEndpoint = $_ENV['API_ENDPOINT'] ?? 'default';

// Using the service
/** @var \Tourze\EnvManageBundle\Service\EnvService $envService */
$publicVars = $envService->fetchPublicArray();

// In Twig templates
{{ env_value('API_ENDPOINT') }}
```

Configuration
-------------

[](#configuration)

Security Configuration
----------------------

[](#security-configuration)

The bundle automatically blocks dangerous environment variables:

- `LD_PRELOAD` - Prevents injection attacks
- `APP_*` - Protects Symfony core configuration
- `DATABASE_*` - Prevents database credential override
- `REDIS_*` - Protects cache configuration
- `JWT_*` - Secures authentication tokens
- `MESSENGER_*` - Protects message queue configuration
- `LOCK_*` - Prevents lock mechanism tampering

Admin Interface
---------------

[](#admin-interface)

Add to your EasyAdmin dashboard:

```
# config/packages/easy_admin.yaml
easy_admin:
    entities:
        Env:
            class: Tourze\EnvManageBundle\Entity\Env
            controller: Tourze\EnvManageBundle\Controller\Admin\EnvCrudController
```

Caching
-------

[](#caching)

Environment variables are cached for 24 hours and automatically invalidated when:

- Any environment variable is created, updated, or deleted
- Cache is manually cleared
- Application is deployed

Events and Extension Points
---------------------------

[](#events-and-extension-points)

### Event Listeners

[](#event-listeners)

The bundle listens to:

- `KernelEvents::REQUEST` - Load variables for HTTP requests
- `WorkerStartedEvent` - Load variables for message workers
- `ConsoleEvents::COMMAND` - Load variables for CLI commands (except cache commands)

### Entity Events

[](#entity-events)

Doctrine entity listeners automatically clear cache on:

- `postPersist` - After creating new variables
- `postUpdate` - After updating variables
- `postRemove` - After deleting variables

Advanced Usage
--------------

[](#advanced-usage)

### Custom Environment Service

[](#custom-environment-service)

```
use Tourze\EnvManageBundle\Service\EnvService;

class MyEnvService implements EnvService
{
    public function fetchPublicArray(): array
    {
        // Custom logic for public variables
    }
}
```

### JSON-RPC Integration

[](#json-rpc-integration)

```
// Expose environment variables via JSON-RPC
$procedure = new GetEnvConfig($envService);
$result = $procedure->execute();
```

Documentation
-------------

[](#documentation)

- [Entity Design](ENTITY_DESIGN.md) - Database schema and entity details
- [Workflow](WORKFLOW.md) - Visual workflow diagrams
- [API Reference](docs/api.md) - Complete API documentation

Testing
-------

[](#testing)

```
# Run tests
./vendor/bin/phpunit packages/env-manage-bundle/tests

# Run static analysis
php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/env-manage-bundle
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Development Standards

[](#development-standards)

- Follow PSR-12 coding standards
- Write tests for new features
- Run PHPStan (level 5) before submitting
- Update documentation as needed
- Add meaningful commit messages

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tourze Team](https://github.com/tourze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Copyright (c) tourze. Please see [License File](LICENSE) for more information.

Changelog
---------

[](#changelog)

See [Releases](https://packagist.org/packages/tourze/env-manage-bundle#releases) for version history and upgrade notes.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance79

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Every ~20 days

Recently: every ~50 days

Total

13

Last Release

140d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-env-manage-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-env-manage-bundle/health.svg)](https://phpackages.com/packages/tourze-env-manage-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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