papimod/dotenv

Module Papi

Installs: 158

Dependents: 5

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 1

pkg:composer/papimod/dotenv

v2.1.0 2025-12-18 14:37 UTC

This package is auto-updated.

Last update: 2025-12-18 14:54:30 UTC


README

Description

Load .env when building your papi. This module uses gitvlucas/phpdotenv.

Configuration

PAPI_DOTENV_DIRECTORY (CONSTANT)

Required No
Type string
Description Directory where the .env file to load is located
Default Root of your project

PAPI_DOTENV_FILE (CONSTANT)

Required No
Type string
Description Custom .env file name
Default .env

Usage

Create a .env file:

ENVIRONMENT=PRODUCTION

HELLO=WORLD

Import the module when creating your application:

require __DIR__ . "/../vendor/autoload.php";

use Papi\PapiBuilder;
use Papimod\Dotenv\DotEnvModule;
use function DI\create;

define("PAPI_DOTENV_DIRECTORY", __DIR__); # Optionnal
define("PAPI_DOTENV_FILE", ".env"); # Optionnal

$builder = new PapiBuilder();

$builder->setModule(DotEnvModule::class)
    ->build()
    ->run();

Use your environment variables anywhere in your code:

var_dump($_ENV["HELLO"] === "WORLD"); // true