railken/dotenv

v0.1.2 2018-12-27 17:20 UTC

This package is auto-updated.

Last update: 2024-09-28 07:08:43 UTC


README

Build Status

此库是 Dotenv 的扩展,允许您更新 .env 文件中的变量。您可以更新、追加或删除变量。

需求

PHP 7.1 及更高版本。

安装

您可以通过 Composer 安装,输入以下命令

composer require railken/dotenv

用法

简单用法如下

use Railken\Dotenv\Dotenv;

// Location of the directory that contains the .env file
$path = __DIR__; 

$dotenv = new Dotenv($path);
$dotenv->load();

$dotenv->updateVariable("APP_KEY", "foo");
$dotenv->appendVariable("NEW_KEY", 2);
$dotenv->removeVariable("NEW_KEY");

Railken\Dotenv\Dotenv 仅仅扩展了类 Dotenv\Dotenv,如您所见 这里

如果您愿意,可以直接使用 Railken\Dotenv\Storage

use Railken\Dotenv\Storage;

// Location of the directory that contains the .env file
$path = __DIR__; 

$storage = new Storage($path);
$storage->update("APP_KEY", "foo");
$storage->append("NEW_KEY", 2);
$storage->remove("NEW_KEY");