PHPackages                             naingaunglwin-dev/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. naingaunglwin-dev/dotenv

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

naingaunglwin-dev/dotenv
========================

Simple and lightweight php dotenv library

2.0.0(9mo ago)09MITPHPPHP ^8.2CI passing

Since Feb 23Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/naingaunglwin-dev/dotenv)[ Packagist](https://packagist.org/packages/naingaunglwin-dev/dotenv)[ RSS](/packages/naingaunglwin-dev-dotenv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Simple Dotenv Library
=====================

[](#simple-dotenv-library)

[![GitHub CI Status](https://github.com/naingaunglwin-dev/dotenv/actions/workflows/tests.yml/badge.svg)](https://github.com/naingaunglwin-dev/dotenv/actions)[![Code Coverage](https://camo.githubusercontent.com/0c967d746eb7f4fe28065a3b94d23faa207cd6f4a968535b20fce0310a87cf89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e)](https://github.com/naingaunglwin-dev/dotenv/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/naingaunglwin-dev/dotenv/blob/main/LICENSE)

About
-----

[](#about)

`NAL\Dotenv` is a flexible and lightweight PHP environment loader designed for modern applications. It supports loading environment variables from `.env` and `.json` files by default, with the ability to register custom loaders (e.g., YAML, XML) effortlessly.

**This package provides:**

- Grouped access to related environment keys
- Support for multiple environment files
- Static or instance-based access
- Optional caching for performance
- Convention-based parser resolution
- Seamless integration with custom loaders and parsers

It's ideal for both small-scale projects and larger applications where managing structured and multi-source environment data is essential.

Contributing
------------

[](#contributing)

- This is an open-source library, and contributions are welcome.
- If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the project repository.

Requirement
-----------

[](#requirement)

- **PHP** version 8.2 or newer is required

Installation &amp; Setup
------------------------

[](#installation--setup)

### Using Composer

[](#using-composer)

> If Composer is not installed, follow the [official guide](https://getcomposer.org/download/).

1. Create a `composer.json` file at your project root directory (if you don't have one):

```
{
  "require": {
    "naingaunglwin-dev/dotenv": "^2.0"
  }
}
```

- Run the following command in your terminal from the project's root directory:

```
composer install
```

If you already have `composer.json` file in your project, just run this command in your terminal,

```
composer require naingaunglwin-dev/dotenv
```

Features
--------

[](#features)

✅ **Load .env files easily**

- Supports standard .env key-value files for environment configuration.

✅ **Support for .json config files**

- Load structured environment data from JSON files — great for frontend-backend monorepo setups.

✅ **Nested key flattening**

- Nested JSON keys are automatically flattened into uppercase ENV\_STYLE\_KEYS.

✅ **Environment grouping support**

- Automatically organizes keys into groups based on naming conventions like APP\_ENV → APP group.

✅ **Custom Loader Registry**

- Register your own loaders to support formats like YAML, TOML, etc.

✅ **Optional override behavior**

- Configure whether later files can override previously loaded keys.

✅ **Safe loading**

- Use `safeLoad()` to prevent exceptions when loading optional or missing files.

✅ **Supercharged access methods**

- Access environment values using `Env::get('KEY')` or grouped access with `Env::group('APP')`.

✅ **Supports multiple files**

- Pass an array of files to load them in order — useful for layering config.

Usage
-----

[](#usage)

```
