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

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

rammewerk/environment
=====================

A simple and fast environment variable handler for PHP projects.

1.2.0(1y ago)263MITPHPPHP &gt;=8.4

Since Dec 14Pushed 1y ago2 watchersCompare

[ Source](https://github.com/rammewerk/environment)[ Packagist](https://packagist.org/packages/rammewerk/environment)[ Docs](https://rammewerk.com)[ RSS](/packages/rammewerk-environment/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Rammewerk Environment
=====================

[](#rammewerk-environment)

A **fast**, **typed**, and **opinionated** environment variable handler designed for simplicity.

This package provides a streamlined, dependency-free approach to handling `.env` files in your project, offering both speed and type safety. Unlike other solutions, Rammewerk Environment focuses on performance and ensures minimal exposure risks by not injecting variables into $\_ENV.

#### Why choose Rammewerk Environment?

[](#why-choose-rammewerk-environment)

- **Blazing fast parsing** of .env files, suitable for high-performance applications.
- **Type-safe outputs**: Automatically converts values to proper types like bool, int, null, or even array.
- **No hidden magic**: Variables are not automatically added to global environment arrays.
- **Dependency-free**: Minimal footprint for lightweight projects.
- **Extensible validation**: Easily validate required variables using closures.
- **Multiple file support**: Load and manage multiple .env files with ease.

***Note**: This package supports a simplified .env format, with specific rules for variable names, comments, and values. See [Limitations](#Limitations) for details.*

Getting Started
---------------

[](#getting-started)

```
$ composer require rammewerk/environment

```

```
use Rammewerk\component\environment\src\Environment;

$env = new Environment();

// Load from environment variable file
$env->load( ROOT_DIR . '.env');

// Get value from environment
$debug_mode = $env->get( 'DEBUG_MODE' );

// Or use the built-in typed getters which returns true or false, defaults to false
$debug_mode = $env->getBool('DEBUG_MODE');
```

Support for multiple .env files
-------------------------------

[](#support-for-multiple-env-files)

You can add multiple environment files or create new variables on the fly.

A file does not necessarily need to be .env. For instance, a file.txt will also work as long as it is correctly formatted.

```
$env->load( ROOT_DIR . '.env');

# Warning: will overwrite value for keys that exist in both files.
$env->load( ROOT_DIR . '.env-app');

# You can also define new variables or overwrite values on the fly.
$env->set('NEW_KEY', 'new value');
```

Validating environment variables
--------------------------------

[](#validating-environment-variables)

```
$env->validate( static function(Validator $env) {
    $env->require('DEBUG_MODE')->isBoolean();
    $env->ifPresent('APP_URL')->endWith('/');
})
```

Limitations
-----------

[](#limitations)

This is a simple env parser. You will need to format your env-files accordingly:

#### Variable names

[](#variable-names)

Environment variable names must consist solely of letters, digits, and the underscore ( \_ ) and must not begin with a digit.

#### Comments

[](#comments)

Comments are **only** allowed on new lines, never on the same line as variables.

```
# This is a valid comment
USER=John # Comment like this is not allowed!
```

#### Variable values

[](#variable-values)

Values can be quoted.

```
# Values can be quoted. These are all the same values:
KEY1=value
KEY2='value'
KEY3="value"
```

### Values will be trimmed and converted to types

[](#values-will-be-trimmed-and-converted-to-types)

```
# Values will be automatically trimmed. This is the same as KEY2='HELLO'
KEY4=' HELLO '

# TRUE or FALSE will be converted to valid boolean type in PHP. If you use quotes, it will be converted to string.
KEY5=TRUE

# An interger value will be converted to a valid PHP interger. If you use quotes, it will be converted to string.
KEY6=120

# Empty string '' or NULL will be converted to PHP NULL value.
KEY7=NULL

# Add commaseparated string inside brackets to convert to array of strings
KEY9='[value1,value2,value3]'
```

Tips
----

[](#tips)

A `new Environment()` will return a new instance of the class. So, if you use a dependency injection container or similar, consider making the Environment class a shared instance. Or make your own singleton wrapper.

Typed getters
-------------

[](#typed-getters)

You can use typed getters to get the value of a key as a specific type. For example:

```
$env->getString('KEY1'); // Returns string or null
$env->getInt('KEY2'); // Returns int or null
$env->getFloat('KEY3'); // Returns float or null
$env->getBool('KEY4'); // Returns bool, true or false, defaults to false
$env->getArray('KEY5'); // Returns array or null
```

Contribution
------------

[](#contribution)

If you have any issues or would like to contribute to the development of this library, feel free to open an issue or pull request.

License
-------

[](#license)

The Rammewerk Container is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% 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 ~254 days

Total

4

Last Release

534d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.2

1.1.0PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/120019460?v=4)[RAMMEWERK](/maintainers/rammewerk)[@rammewerk](https://github.com/rammewerk)

---

Top Contributors

[![rammewerk](https://avatars.githubusercontent.com/u/120019460?v=4)](https://github.com/rammewerk "rammewerk (4 commits)")[![follestad](https://avatars.githubusercontent.com/u/32802271?v=4)](https://github.com/follestad "follestad (3 commits)")

---

Tags

dotenvenvironmentphprammewerk-componentenvironmentenvdotenv

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

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

13.5k640.2M6.3k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k243.3M2.8k](/packages/symfony-dotenv)[diarmuidie/envpopulate

Tool to interactively populate a `.env` file based on an `.env.example` file whenever Composer installs or updates.

1695.7k](/packages/diarmuidie-envpopulate)[zepgram/magento-dotenv

Simple autoloader to integrate the Symfony Dotenv component into Magento2

1376.0k](/packages/zepgram-magento-dotenv)[nystudio107/dotenvy

Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents.

317.0k](/packages/nystudio107-dotenvy)[dotenv-org/phpdotenv-vault

Load environment variables from encrypted .env.vault files

1019.5k2](/packages/dotenv-org-phpdotenv-vault)

PHPackages © 2026

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