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

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

alanvdb/server-environment
==========================

v1.0(1y ago)021MITPHP

Since May 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Alanvdb/server-environment)[ Packagist](https://packagist.org/packages/alanvdb/server-environment)[ RSS](/packages/alanvdb-server-environment/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

PHP Server Environment
======================

[](#php-server-environment)

A PHP library for managing environment variables with strict type checking and comprehensive error handling.

Features
--------

[](#features)

- Secure environment variable management
- Strict type enforcement
- Immutable system environment variables
- Easy-to-use interface for retrieving environment variables
- Comprehensive exception handling

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

[](#installation)

Install via Composer:

```
composer require alanvdb/server-environment
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use AlanVdb\Server\ServerEnvironment;

// Create an environment with optional initial variables
$env = new ServerEnvironment([
    'APP_DEBUG' => 'true',
    'APP_ENV' => 'development'
]);

// Retrieve an environment variable
$debugMode = $env->get('APP_DEBUG'); // returns 'true'

// Check if a variable exists
$hasEnv = $env->has('APP_ENV'); // returns true
```

### Error Handling

[](#error-handling)

```
use AlanVdb\Server\Exception\EnvironmentVariableNotFound;
use AlanVdb\Server\Exception\CannotMutateEnvironmentVariable;

try {
    // Attempting to get a non-existent variable will throw an exception
    $value = $env->get('NON_EXISTENT_VAR');
} catch (EnvironmentVariableNotFound $e) {
    // Handle missing variable
}

try {
    // Attempting to modify a system environment variable will throw an exception
    $env = new ServerEnvironment(['PATH' => '/custom/path']);
} catch (CannotMutateEnvironmentVariable $e) {
    // Handle mutation attempt
}
```

Factory
-------

[](#factory)

```
use AlanVdb\Server\ServerEnvironmentFactory;

$factory = new ServerEnvironmentFactory();
$env = $factory->create([
    'APP_DEBUG' => 'true',
    'APP_ENV' => 'development'
]);
```

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

[](#requirements)

- PHP 8.2+
- Composer

Key Design Principles
---------------------

[](#key-design-principles)

- Immutability of system environment variables
- Type safety
- Clear and descriptive exceptions
- Easy integration with existing PHP projects

License
-------

[](#license)

[MIT License](LICENSE)

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance46

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

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

Unknown

Total

1

Last Release

414d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35227520?v=4)[Alan Van Den Bosch](/maintainers/alanvdb)[@Alanvdb](https://github.com/Alanvdb)

---

Top Contributors

[![Alanvdb](https://avatars.githubusercontent.com/u/35227520?v=4)](https://github.com/Alanvdb "Alanvdb (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[eventsauce/backoff

Back-off strategy interface

70848.9k8](/packages/eventsauce-backoff)

PHPackages © 2026

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