cleaniquecoders/php-env-key-manager
Composer 安装命令:
composer require cleaniquecoders/php-env-key-manager
包简介
A framework-agnostic PHP package for easy .env file key management. Seamlessly update, add, or modify environment variables across projects with minimal configuration.
README 文档
README
A framework-agnostic PHP package for easy .env file key management. Seamlessly update, add, or modify environment variables across projects with minimal configuration.
Installation
You can install the package via composer:
composer require cleaniquecoders/php-env-key-manager
Usage
Basic Usage
Following are the basic usage examples for the package:
use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; // Path to your .env file $envFilePath = __DIR__ . '/.env'; $envManager = new EnvKeyManager($envFilePath); // Set a key $envManager->setKey('APP_DEBUG', 'true'); // Disable a key $envManager->disableKey('APP_DEBUG'); // Enable a key $envManager->enableKey('APP_DEBUG');
Framework-Specific Examples
Laravel
To use EnvKeyManager in a Laravel application, register it as a singleton in the AppServiceProvider to allow easy access across your application.
Laravel Usage
-
Register as a Singleton
In
App\Providers\AppServiceProvider:use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; public function register() { $this->app->singleton(EnvKeyManager::class, function ($app) { return new EnvKeyManager($app->environmentFilePath()); }); }
-
Usage in a Command
Create a Laravel Artisan command to set, disable, or enable environment keys:
<?php namespace App\Console\Commands; use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; use Illuminate\Console\Command; class ManageEnvKeyCommand extends Command { protected $signature = 'env:manage-key {action} {key} {value?}'; protected $description = 'Manage an environment key'; protected $envManager; public function __construct(EnvKeyManager $envManager) { parent::__construct(); $this->envManager = $envManager; } public function handle() { $action = $this->argument('action'); $key = $this->argument('key'); $value = $this->argument('value'); switch ($action) { case 'set': $this->envManager->setKey($key, $value); $this->info("Key {$key} set to {$value}."); break; case 'disable': $this->envManager->disableKey($key); $this->info("Key {$key} has been disabled."); break; case 'enable': $this->envManager->enableKey($key); $this->info("Key {$key} has been enabled."); break; default: $this->error("Invalid action. Use 'set', 'disable', or 'enable'."); } } }
Symfony
To use EnvKeyManager in Symfony, initialize it with the .env path, and use it in Symfony commands or services.
Symfony Usage
-
Initialize
EnvKeyManagerwith Symfony’s.envpath.use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; $envFilePath = __DIR__ . '/../../.env'; // Adjust the path to your Symfony .env file $envManager = new EnvKeyManager($envFilePath);
-
Use in a Symfony Command
Create a Symfony console command to manage environment keys:
<?php namespace App\Command; use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ManageEnvKeyCommand extends Command { protected static $defaultName = 'env:manage-key'; private $envManager; public function __construct(EnvKeyManager $envManager) { parent::__construct(); $this->envManager = $envManager; } protected function configure() { $this ->setDescription('Manage an environment key') ->addArgument('action', InputArgument::REQUIRED, 'Action: set, disable, enable') ->addArgument('key', InputArgument::REQUIRED, 'The environment key') ->addArgument('value', InputArgument::OPTIONAL, 'The value for set action'); } protected function execute(InputInterface $input, OutputInterface $output) { $action = $input->getArgument('action'); $key = $input->getArgument('key'); $value = $input->getArgument('value'); switch ($action) { case 'set': $this->envManager->setKey($key, $value); $output->writeln("Key {$key} set to {$value}."); break; case 'disable': $this->envManager->disableKey($key); $output->writeln("Key {$key} has been disabled."); break; case 'enable': $this->envManager->enableKey($key); $output->writeln("Key {$key} has been enabled."); break; default: $output->writeln("Invalid action. Use 'set', 'disable', or 'enable'."); return Command::FAILURE; } return Command::SUCCESS; } }
CodeIgniter
To use EnvKeyManager in CodeIgniter, initialize it with the .env path and use it within controllers or custom classes.
CodeIgniter Usage
-
Initialize
EnvKeyManagerwith the CodeIgniter.envpath.use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; $envFilePath = ROOTPATH . '.env'; // CodeIgniter base path to .env $envManager = new EnvKeyManager($envFilePath);
-
Use in a CodeIgniter Controller
Create a CodeIgniter controller method to manage environment keys:
<?php namespace App\Controllers; use CleaniqueCoders\PhpEnvKeyManager\EnvKeyManager; class EnvController extends BaseController { protected $envManager; public function __construct() { $this->envManager = new EnvKeyManager(ROOTPATH . '.env'); } public function manageKey($action, $key, $value = null) { switch ($action) { case 'set': $this->envManager->setKey($key, $value); return "Key {$key} set to {$value}."; case 'disable': $this->envManager->disableKey($key); return "Key {$key} has been disabled."; case 'enable': $this->envManager->enableKey($key); return "Key {$key} has been enabled."; default: return "Invalid action. Use 'set', 'disable', or 'enable'."; } } }
These framework-specific examples demonstrate how to integrate EnvKeyManager seamlessly in Laravel, Symfony, and CodeIgniter, making it easy to manage environment keys within each framework.
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.
cleaniquecoders/php-env-key-manager 适用场景与选型建议
cleaniquecoders/php-env-key-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 962 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cleaniquecoders」 「php-env-key-manager」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cleaniquecoders/php-env-key-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cleaniquecoders/php-env-key-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cleaniquecoders/php-env-key-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generate running number when creating new records in your table.
Generate Database Schema Documentation
Keep track all the emails sent in the your Laravel application.
Common Contracts for Laravel
Simple Actionable for Laravel
Generate Database Schema Documentation
统计信息
- 总下载量: 962
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-11