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

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

xdg/environment
===============

An abstraction layer over environment variables.

2.1(3y ago)08701MITPHPPHP &gt;=8.1

Since Oct 8Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (1)

xdg/environment
===============

[](#xdgenvironment)

[![codecov](https://camo.githubusercontent.com/034b4785781bf4527d2579d443386fdc827ac5cd0a9ec942b801a19d38931408/68747470733a2f2f636f6465636f762e696f2f67682f7068702d7864672f656e7669726f6e6d656e742f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d5145363732554b325a47)](https://codecov.io/gh/php-xdg/environment)

An abstraction layer over environment variables.

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

[](#installation)

```
composer require xdg/environment
```

Usage
-----

[](#usage)

The library consists of several classes implementing the `Xdg\Environment\EnvironmentProviderInterface`:

```
use Xdg\Environment\XdgEnvironment;
use Xdg\Environment\Provider\ArrayProvider;
use Xdg\Environment\Provider\ChainProvider;
use Xdg\Environment\Provider\EnvSuperGlobalProvider;
use Xdg\Environment\Provider\GetenvProvider;
use Xdg\Environment\Provider\ServerSuperGlobalProvider;

// fetches values from the $_ENV super-global
$env = new EnvSuperGlobalProvider();
$value = $env->set('FOO', 'bar');
assert($env->get('FOO') === $value);
assert($_ENV['FOO'] === $value);

$env->unset('FOO');
assert($env->get('FOO') === null);
assert(!isset($_ENV['FOO']));

// fetches values from the $_SERVER super-global
$env = new ServerSuperGlobalProvider();

// fetches values using the getenv() function
$env = new GetenvProvider();

// fetches values using the provided array as a backing store (useful for testing)
$env = new ArrayProvider(['FOO' => 'bar']);

// fetches values from a chain of providers, returning the first non-null value found.
$env = new ChainProvider(
    new ServerSuperGlobalProvider(),
    new EnvSuperGlobalProvider(),
    new GetenvProvider(),
);
// as a shortcut for the former, you can use:
$env = XdgEnvironment::default();
// when updating a value, all providers in the chain are updated:
$env->set('FOO', 'bar');
assert($_SERVER['FOO'] === 'bar')
assert($_ENV['FOO'] === 'bar')
assert(getenv('FOO') === 'bar')
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~52 days

Total

4

Last Release

1162d ago

Major Versions

0.1.0 → 1.02023-02-03

1.0 → 2.02023-03-01

### Community

Maintainers

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

---

Top Contributors

[![ju1ius](https://avatars.githubusercontent.com/u/218404?v=4)](https://github.com/ju1ius "ju1ius (16 commits)")

---

Tags

environmentenvironment variablesfreedesktopxdg

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k226.7M2.3k](/packages/symfony-dotenv)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[wolfcast/browser-detection

The Wolfcast BrowserDetection PHP class facilitates the identification of the user's environment such as Web browser, version, platform family, platform version or if it's a mobile device or not.

1391.0M7](/packages/wolfcast-browser-detection)[imliam/laravel-env-set-command

Set a .env file variable from the command line

118352.4k10](/packages/imliam-laravel-env-set-command)[silverstripe/environmentcheck

Provides an API for building environment tests

35503.8k13](/packages/silverstripe-environmentcheck)

PHPackages © 2026

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