PHPackages                             nitier/environment - 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. nitier/environment

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

nitier/environment
==================

Environment variables

0.1.1(1y ago)03MITPHP

Since Dec 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Nitier/Environment)[ Packagist](https://packagist.org/packages/nitier/environment)[ RSS](/packages/nitier-environment/feed)WikiDiscussions main Synced 1mo ago

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

Nitier Environment
==================

[](#nitier-environment)

A lightweight PHP library for managing environment variables from different formats such as `.env`, YAML, and JSON files. This library allows you to load environment variables from various sources, clean and cast values, and access environment variables conveniently.

Features
--------

[](#features)

- Load environment variables from `.env`, YAML, and JSON files.
- Support for automatic type casting (e.g., boolean, null, integers, floats, arrays, and objects).
- Support for serialized objects and JSON objects.
- Easy-to-use interface to access environment variables.
- Customizable root path for configuration files.

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

[](#requirements)

- PHP 7.4 or higher.
- Symfony YAML component (for YAML file support).

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

[](#installation)

You can install the library via Composer:

```
composer require nitier/environment
```

If you need support for YAML files, install the `symfony/yaml` package:

```
composer require symfony/yaml
```

Usage
-----

[](#usage)

### 1. Setting the Root Path

[](#1-setting-the-root-path)

To set the root path for your project (where `.env` and configuration files are located), use the `setRoot` method.

```
use Nitier\Environment;

Environment::setRoot('/path/to/your/project');
```

### 2. Loading Environment Variables from `.env`

[](#2-loading-environment-variables-from-env)

You can load environment variables from a `.env` file by using the `load` method. This will automatically parse the `.env` file and populate the environment variables.

```
Environment::load('/path/to/.env');
```

If the `.env` file is located in the default root path, you can call:

```
Environment::load();
```

### 3. Loading Environment Variables from YAML

[](#3-loading-environment-variables-from-yaml)

To load variables from a YAML file, use the `loadYaml` method:

```
Environment::loadYaml('/path/to/config.yml');
```

### 4. Loading Environment Variables from JSON

[](#4-loading-environment-variables-from-json)

To load environment variables from a JSON file, use the `loadJson` method:

```
Environment::loadJson('/path/to/config.json');
```

### 5. Accessing Environment Variables

[](#5-accessing-environment-variables)

You can retrieve environment variables using the `get` method:

```
$value = Environment::get('VARIABLE_NAME', 'default_value');
```

### 6. Setting Environment Variables

[](#6-setting-environment-variables)

To manually set an environment variable:

```
Environment::set('VARIABLE_NAME', 'value');
```

You can also unset a variable by passing `null` as the value:

```
Environment::set('VARIABLE_NAME', null);
```

### 7. Getting All Environment Variables

[](#7-getting-all-environment-variables)

To retrieve all environment variables as an associative array:

```
$variables = Environment::all();
```

### 8. Advanced Value Casting

[](#8-advanced-value-casting)

The library supports automatic casting of values:

- `'null'` will be cast to `null`.
- `'true'` and `'false'` will be cast to `true` and `false`, respectively.
- Numeric values will be cast to `int` or `float`.
- JSON and serialized objects will be parsed accordingly.

### Example Usage

[](#example-usage)

```
use Nitier\Environment;

// Set root path for configuration files
Environment::setRoot('/path/to/project');

// Load variables from .env file
Environment::load();

// Get an environment variable
$envVar = Environment::get('DATABASE_URL');

// Get all environment variables
$allVars = Environment::all();

// Set an environment variable manually
Environment::set('NEW_VAR', 'value');
```

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

[](#contributing)

If you would like to contribute to this library, please fork the repository and submit a pull request. Make sure to write tests for any new features or bug fixes.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

517d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1699f8ad2da82ebad82eb74d3392f6989ba9f1d903ee06410f861881af5fade?d=identicon)[Nitier](/maintainers/Nitier)

---

Top Contributors

[![Nitier](https://avatars.githubusercontent.com/u/185420306?v=4)](https://github.com/Nitier "Nitier (6 commits)")

### Embed Badge

![Health badge](/badges/nitier-environment/health.svg)

```
[![Health](https://phpackages.com/badges/nitier-environment/health.svg)](https://phpackages.com/packages/nitier-environment)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
