定制 mahbubhelal/sync-env 二次开发

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

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

mahbubhelal/sync-env

最新稳定版本:v1.3

Composer 安装命令:

composer require --dev mahbubhelal/sync-env

包简介

A laravel package to sync env variables between different .env files.

README 文档

README

A highly opinionated Laravel package to sync environment variables between different .env files and view differences between them. Ensures all your .env files are consistent, clean, and strictly follow best practices for key/value formatting.

Features

  • Strict .env key rules: Only allows keys that are upper snake case, starting with an uppercase letter and containing only uppercase letters, numbers, or underscores (minimum 2 characters).
  • No leading/trailing spaces: No line in any .env file may have leading or trailing spaces. Values must not have leading or trailing spaces.
  • Identical structure: The synced .env files will have the exact same structure, order, comments, and blank lines as .env.example, differing only in values where present.
  • Sync .env files: Synchronize keys from .env.example to all other .env* files, preserving existing values and creating backups.
  • Show diffs: View differences between .env.example and other .env files, including options to show all keys or include backup files.
  • Backup management: Automatically create backups before syncing, and remove old backups with options.

Key Format Rules

  • Keys must be in UPPER_SNAKE_CASE.
  • Keys must start with an uppercase letter (A-Z).
  • Keys must be at least 2 characters long.
  • Keys may only contain uppercase letters (A-Z), numbers (0-9), and underscores (_).
  • No leading or trailing spaces are allowed in any line.
  • Values must not have leading or trailing spaces.

Examples

Valid keys:

APP_NAME
DB_CONNECTION
FOO_BAR_123

Invalid keys:

app_name        # not uppercase
A               # single character not allowed
_DB_CONNECTION  # cannot start with underscore
 APP_NAME       # leading space
APP-NAME        # dash not allowed
APP NAME        # space not allowed
APP@NAME        # special char not allowed

Invalid values:

APP_NAME= MyApp     # leading space in value
APP_NAME=MyApp      # trailing space in value

Installation

composer require mahbubhelal/sync-env

Usage

1. Sync .env files

Synchronize .env.example to all other .env* files:

php artisan sync-env:example-to-envs

Options:

  • --no-backup (-N): Do not create a backup of the target .env file before syncing.
  • --remove-backups (-r): Remove previously created backup files before syncing.
  • -v (verbose): Show detailed warnings about comment differences, key position differences, and additional keys in target files.

2. Show differences between .env files

Display differences between .env.example and other .env files:

php artisan sync-env:show-diffs

Options:

  • --all (-a): Show all keys, including identical ones.
  • --include-backup (-b): Include backup files in the diff view.
  • --only=: Only show specific env files (comma-separated, e.g., --only=.env,.env.staging).
  • --exclude=: Exclude specific env files (comma-separated, e.g., --exclude=.env.testing).

Note: At least 2 env files are required. If --only or --exclude results in fewer than 2 files, .env.example is automatically included.

Example Workflow

  1. Update your .env.example file with new keys or changes, following the strict key/value rules above.
  2. Run the sync command to propagate changes to all .env files:
    php artisan sync-env:example-to-envs
  3. Use the show-diffs command to review differences:
    php artisan sync-env:show-diffs

Testing

Run tests with Pest:

vendor/bin/pest

License

MIT

Author: Md Mahbub Helal (mdhelal00@gmail.com)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固