/dotenv

This library is an extension of vlucas/phpdotenv that grants you the ability to update variables into the `.env` file. You can either update, append or remove a variable.

Primary LanguagePHPMIT LicenseMIT

dotenv

Build Status

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.

Requirements

PHP 7.1 and later.

Installation

You can install it via Composer by typing the following command:

composer require railken/dotenv

Usage

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");