amdadulhaq/env-editor-laravel
最新稳定版本:v2.0.0
Composer 安装命令:
composer require amdadulhaq/env-editor-laravel
包简介
ENV Editor for laravel
README 文档
README
Simple and powerful ENV file editor for your Laravel application.
Installation
You can install the package via composer:
composer require amdadulhaq/env-editor-laravel
Usage
Basic Methods
use AmdadulHaq\EnvEditor\EnvEditor; // Set a new key or update an existing one EnvEditor::set('APP_NAME', 'MyApp'); // Update an existing key (throws exception if key doesn't exist) EnvEditor::update('APP_NAME', 'MyApp'); // Set or update (smart - checks if key exists) EnvEditor::setOrUpdate('APP_NAME', 'MyApp'); // Remove a key EnvEditor::remove('APP_NAME');
Reading Values
// Get a single value $appName = EnvEditor::get('APP_NAME'); $appName = EnvEditor::get('NON_EXISTENT_KEY', 'default_value'); // with default // Get all values as an array $allEnv = EnvEditor::getAll(); // Check if a key exists $hasKey = EnvEditor::has('APP_NAME');
Backup and Restore
// Create a backup (auto-generates timestamp-based filename) $backupPath = EnvEditor::backup(); // Create a backup with custom name $backupPath = EnvEditor::backup('backup-before-deployment.env'); // List all available backups $backups = EnvEditor::listBackups(); // Restore from a backup EnvEditor::restore('backup-before-deployment.env');
Using with Dependency Injection
use AmdadulHaq\EnvEditor\EnvEditor; class SomeService { public function __construct( protected EnvEditor $envEditor ) {} public function updateSettings() { $this->envEditor->set('SOME_KEY', 'value'); $value = $this->envEditor->get('SOME_KEY'); } }
Custom ENV File Path
If you need to work with a different .env file:
$editor = new EnvEditor('/path/to/custom/.env'); $editor->set('KEY', 'value');
Features
- ✅ Read, write, and update .env file values
- ✅ Check if keys exist
- ✅ Get all environment variables as an array
- ✅ Backup and restore .env files
- ✅ Handle values with spaces, quotes, and special characters
- ✅ Dependency injection support
- ✅ Custom .env file path support
- ✅ Comprehensive error handling
- ✅ Full test coverage with Pest
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 258
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-19