nathanlesage / envedit
一个简单的类,用于通过PHP编辑项目中.env文件。
v0.1.2
2017-06-04 19:22 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-27 22:14:12 UTC
README
一个简单的类,用于通过PHP编辑项目中.env文件。
为什么通过PHP编辑.env文件?
通常,.env文件由开发者用于适应当前环境,如生产、开发、本地等。为了适应这些环境,有必要存储不同环境的不同凭证(如数据库用户名和密码等)。
但是,如果您正在开发一个依赖于.env文件并需要分发给最终用户的应用程序,您不能假设他们知道哪些.env文件的值是正确的,哪些是不正确的。此外,您可能不希望您的最终用户总是通过SSH连接到您的服务器来编辑文件,而是通过一个舒适的GUI来编辑。因此,这个库可以让你轻松地读取.env文件,编辑值,并用新的变量重新写入文件。
安装
您可以通过composer轻松安装它
$ composer require nathanlesage/envedit
用法
您只需与EnvEdit类进行交互。您可以通过将文件的路径传递给一个新的EnvEdit对象来访问您的.env文件
use NathanLeSage\EnvEdit; ... $editor = new EnvEdit('/path/to/your/.env'); // Read and parse the file $editor->read(); // Retrieve the value of a specific variable. // Of course, you should normally do this via env('APP_ENVIRONMENT') // or similar. $value = $editor->getValue('APP_ENVIRONMENT'); // Change one or more variables $editor->setVars( ['APP_ENVIRONMENT' => 'production', 'REDIS_HOST' => '123.321.12.32'] ); // Write your changes to file $editor->write(); // You could also retrieve the file's contents without writing them. // This is useful for backup purposes or letting the user control what // will be altered. $editor->getFile();
贡献
如果您想做出贡献,只需将这个库进行分支,并发送包含您更改的pull请求!我感激每一个帮助!
许可
此库受MIT许可证条款约束。