text.skip-to-content

Dotenv

The pyncer/dotenv package implements a phpdotenv adaptor to read and write .env values to constants.

Installation

Install via Composer:

$ composer require pyncer/dotenv

Example

use Dotenv\Dotenv;
use Dotenv\Repository\RepositoryBuilder;
use Pyncer\Dotenv\ConstAdapter;

// ...

$repository = RepositoryBuilder::createWithNoAdapters()
    ->addAdapter(new ConstAdapter('Vendor\\Namespace'))
    ->immutable()
    ->make();

$dotenv = Dotenv::create($repository, getcwd());
$dotenv->load();

// ...

echo \Vendor\Namespace\MY_ENV_VARIABLE;