PHPackages                             kariricode/dotenv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. kariricode/dotenv

ActiveLibrary[Framework](/categories/framework)

kariricode/dotenv
=================

The only PHP dotenv with auto type casting, AES-256-GCM encryption, OPcache caching, fluent validation DSL, environment-aware loading, and CLI tooling — zero dependencies, PHP 8.4+, ARFA 1.3.

v2.0.0(2mo ago)016MITPHPPHP ^8.4CI passing

Since Oct 12Pushed 2mo agoCompare

[ Source](https://github.com/KaririCode-Framework/kariricode-dotenv)[ Packagist](https://packagist.org/packages/kariricode/dotenv)[ Docs](https://kariricode.org)[ RSS](/packages/kariricode-dotenv/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)DependenciesVersions (7)Used By (0)

KaririCode Dotenv
=================

[](#kariricode-dotenv)

[![PHP 8.4+](https://camo.githubusercontent.com/270717987f5341772d79b57567226e54ed27b2d4199bbdc98a96e2edf24902fa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342532422d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/)[![License: MIT](https://camo.githubusercontent.com/1e64768fef09f35b66921728160f533208fd2e3e792a2755187d16c25d535511/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d3232633535652e737667)](LICENSE)[![PHPStan Level 9](https://camo.githubusercontent.com/a812723b363d3726b682e5d739e91f2ade163846054ce3797b9085b84cc61806/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230392d344634364535)](https://phpstan.org/)[![Tests](https://camo.githubusercontent.com/9f5fadae5a7ace264c020acee5095a7f55b1b17a0d39553cf19c8e1eebbd8d1d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d32303525323070617373696e672d323263353565)](https://kariricode.org)[![Zero Dependencies](https://camo.githubusercontent.com/d96960614f3876c99d87adb499854fd9be9d384e813466e9fcf44a73456fc098/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446570656e64656e636965732d302d323263353565)](composer.json)[![ARFA](https://camo.githubusercontent.com/708efab30524ab8fd4e0413edfb4378bb863a71559c4a9b59cdcb7b0ab6f65c0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f415246412d312e332d6f72616e6765)](https://kariricode.org)[![KaririCode Framework](https://camo.githubusercontent.com/bd3e3709bf161ac982b76f7afd06c39afe478d15f2b5e1d47df8606b5c9c03f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4b6172697269436f64652d4672616d65776f726b2d6f72616e6765)](https://kariricode.org)

**The only PHP dotenv with AES-256-GCM encryption, OPcache caching, fluent validation DSL,
environment-aware cascade loading, and auto type casting — zero dependencies, PHP 8.4+.**

[Installation](#installation) · [Quick Start](#quick-start) · [Features](#features) · [Validation DSL](#validation-dsl) · [Encryption](#encryption) · [Architecture](#architecture)

---

The Problem
-----------

[](#the-problem)

Every PHP project reinvents the same wheel:

```
// No type safety — you get raw strings everywhere
$_ENV['DB_PORT']  // "5432" (string, not int)
$_ENV['DEBUG']    // "true" (string, not bool)

// No validation — missing vars discovered at runtime
// No encryption — secrets sit as plaintext in .env files
// No cascade — can't load .env.local over .env automatically
```

The Solution
------------

[](#the-solution)

```
$dotenv = new Dotenv(__DIR__);
$dotenv->load();

// Auto-typed
env('DB_PORT');   // 5432 (int)
env('DEBUG');     // true (bool)

// Validated before service boot
$dotenv->validate()
    ->required('DB_HOST', 'DB_PORT')
    ->isInteger('DB_PORT')->between(1, 65535)
    ->url('APP_URL')
    ->email('ADMIN_EMAIL')
    ->assert();

// Encrypted secrets — transparent decryption
// SECRET=encrypted:base64data...
$dotenv->get('SECRET');  // "my-actual-secret"
```

---

Requirements
------------

[](#requirements)

RequirementVersionPHP8.4 or higherext-opensslOptional (required for encryption)---

Installation
------------

[](#installation)

```
composer require kariricode/dotenv
```

---

Quick Start
-----------

[](#quick-start)

```
# 1. Create your .env
APP_ENV=production
APP_URL=https://myapp.com
DB_HOST=localhost
DB_PORT=5432
APP_DEBUG=false
```

```
