codemonster-ru / env
Lightweight .env loader for PHP projects
v2.0.0
2025-09-28 06:50 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
README
A simple and lightweight .env
loader for PHP projects.
๐ฆ Installation
Via Composer:
composer require codemonster-ru/env
๐ Usage
Create a .env file in the root of your project:
APP_NAME=MyApp FEATURE_ENABLED=true FEATURE_DISABLED=false OPTIONAL_VALUE=null EMPTY_VALUE=empty SSR_URL="http://localhost:3000"
Load .env in your app:
<?php require __DIR__ . '/vendor/autoload.php'; use Codemonster\Env\Env; Env::load(__DIR__ . '/.env'); echo env('APP_NAME'); // "MyApp" var_dump(env('FEATURE_ENABLED')); // true (bool) var_dump(env('FEATURE_DISABLED')); // false (bool) var_dump(env('OPTIONAL_VALUE')); // null var_dump(env('EMPTY_VALUE')); // "" echo env('SSR_URL'); // http://localhost:3000 echo env('NOT_DEFINED', 'default'); // "default"
โจ Features
- Loading
.env
files into$_ENV
,$_SERVER
, and viaputenv()
. - Boolean value support:
true
,(true)
โtrue
false
,(false)
โfalse
- Support for
null
andempty
: null
,(null)
โnull
empty
,(empty)
โ""
- Support for quoted strings
"..."
and'...'
. - Global function
env($key, $default = null)
.
๐งช Testing
You can run tests with the command:
composer test