This library is an extension of Dotenv that grants you the ability to update variables into the .env
file.
You can either update, append or remove a variable.
PHP 7.1 and later.
You can install it via Composer by typing the following command:
composer require railken/dotenv
A simple usage looks like:
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");
The class Railken\Dotenv\Dotenv
simply extends the class Dotenv\Dotenv
as you can see here
If you wish you can use directly the 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");