PHPackages                             damejidlo/envy - 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. damejidlo/envy

Abandoned → [nepada/envy](/?search=nepada%2Fenvy)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

damejidlo/envy
==============

Helpers for extracting, validating and type-casting data from environment variables

v0.1.1(6y ago)14192BSD-3-ClausePHPPHP &gt;=7.3

Since Oct 29Pushed 6y ago5 watchersCompare

[ Source](https://github.com/damejidlo/envy)[ Packagist](https://packagist.org/packages/damejidlo/envy)[ RSS](/packages/damejidlo-envy/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (3)Used By (0)

Envy
====

[](#envy)

[![Build Status](https://camo.githubusercontent.com/c1f1f2a658dd55012ed7c3c9e70a7d40d849921e864619ca5ef6dc1bc2fb3707/68747470733a2f2f7472617669732d63692e6f72672f64616d656a69646c6f2f656e76792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/damejidlo/envy)[![Downloads this Month](https://camo.githubusercontent.com/729818795ff730f6eb15273a15ae86f7d7084a9faf2c55a286dcb18880aa2d7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f64616d656a69646c6f2f656e76792e737667)](https://packagist.org/packages/damejidlo/envy)[![Latest stable](https://camo.githubusercontent.com/56be9175b1c5b20d5591eafd6720ca51ba038b4f0c66814bcea6428efd5b7d77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616d656a69646c6f2f656e76792e737667)](https://packagist.org/packages/damejidlo/envy)

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

[](#installation)

```
$ composer require damejidlo/envy
```

Basic usage
-----------

[](#basic-usage)

Create `Envy instance`:

```
use Damejidlo\Envy\Envy;
use Damejidlo\Envy\LoaderFactory;
use Damejidlo\Envy\ValueProviders\Reader;

$reader = new Reader();
$loaderFactory = new LoaderFactory($reader);
$envy = new Envy($reader, $loaderFactory);
```

`Envy` supports several methods for loading the most common data types from env variables. When loading the value, it is first validated (throws exception on invalid input), and then type-casted.

### String values

[](#string-values)

```
// Get string from `FOO` env variable, or throw exception if not set
$envy->getString('FOO');
// Get string from `FOO` env variable, or return `'default'` if not set
$envy->getString('FOO', 'default');
// Get string from `FOO` env variable, or return `NULL` if not set
$envy->getStringOrNull('FOO');
```

### Boolean values

[](#boolean-values)

There are multiple supported ways of expressing boolean values: `true`/`false`, `yes`/`no`, `1`/`0` (all case insensitive).

```
// Get boolean from `FOO` env variable, or throw exception if not set
$envy->getBool('FOO');
// Get boolean from `FOO` env variable, or return `FALSE` if not set
$envy->getBool('FOO', FALSE);
// Get boolean from `FOO` env variable, or return `NULL` if not set
$envy->getBoolOrNull('FOO');
```

### Integer values

[](#integer-values)

```
// Get integer from `FOO` env variable, or throw exception if not set
$envy->getInt('FOO');
// Get integer from `FOO` env variable, or return `42` if not set
$envy->getInt('FOO', 42);
// Get integer from `FOO` env variable, or return `NULL` if not set
$envy->getIntOrNull('FOO');
```

### Float values

[](#float-values)

```
// Get float from `FOO` env variable, or throw exception if not set
$envy->getFloat('FOO');
// Get float from `FOO` env variable, or return `3.1415` if not set
 $envy->getFloat('FOO', 3.1415);
// Get float from `FOO` env variable, or return `NULL` if not set
$envy->getFloatOrNull('FOO');
```

### Arrays

[](#arrays)

The default item delimiter `~\s*,\s*~` is used to split the items.

#### List of string values

[](#list-of-string-values)

```
// Get array of string from `FOO` env variable, or throw exception if not set
$envy->getStringArray('FOO');
// Get array of strings from `FOO` env variable, or return `['foo']` if not set
$envy->getStringArray('FOO', ['foo']);
// Get array of strings from `FOO` env variable, or return `NULL` if not set
$envy->getStringArrayOrNull('FOO');
```

#### List of integer values

[](#list-of-integer-values)

```
// Get array of integer from `FOO` env variable, or throw exception if not set
$envy->getIntArray('FOO');
// Get array of integers from `FOO` env variable, or return `[42]` if not set
$envy->getIntArray('FOO', [42]);
// Get array of integers from `FOO` env variable, or return `NULL` if not set
$envy->getIntArrayOrNull('FOO');
```

#### List of float values

[](#list-of-float-values)

```
// Get array of float from `FOO` env variable, or throw exception if not set
$envy->getFloatArray('FOO');
// Get array of float from `FOO` env variable, or return `[3.1415]` if not set
$envy->getFloatArray('FOO', [3.1415]);
// Get array of float from `FOO` env variable, or return `NULL` if not set
$envy->getFloatArrayOrNull('FOO');
```

Nette DI integration
--------------------

[](#nette-di-integration)

Register the extension in your configuration, this will register the necessary services in your DI container:

```
extensions:
    envy: Damejidlo\Envy\DI\EnvyExtension
```

You can now use a shorthand notation to access `Envy` methods:

```
parameters:
    loadedFromEnvVariables:
        foo: @envy::getString('FOO')
        bar: @envy::getIntArray('FOO', [1, 1, 2, 3, 5, 8, 13])

services:
    -
        type: MyService
        arguments:
            foo: %loadedFromEnvVariables.foo%
            bar: %loadedFromEnvVariables.bar%
```

Custom loaders
--------------

[](#custom-loaders)

You can create your own loaders with completely customizable processing of loaded values, e.g.:

```
use Damejidlo\Envy\LoaderFactory;
use Damejidlo\Envy\ValueProviders\Reader;

$reader = new Reader();
$loaderFactory = new LoaderFactory($reader);

$defaultValue = ['https://example.com'];

// Processor that will split items on semicolon and validate every item contains valid URL
$arrayProcessor = (new ArrayProcessor())
	->withDelimiter('~;~')
	->withItemValidator('url');

$loader = $loaderFactory->createLoader()
	->withAddedProcessor($arrayProcessor)
	->withValidator('array:1..') // make sure we're loading non-empty array
	->withFallback($defaultValue);

// Get non-empty list of URLs from `FOO_URLS` env variable, or `$defaultValue` if not set
$urls = $loader->get('FOO_URLS');
```

If the default set of processors does not cover your use case, you can write your own by implementing `ProcessorInterface`.

Validation
----------

[](#validation)

The validation is build on top of `Nette\Utils\Validators` - you can validate against any type Nette supports.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

2383d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b4780fe328102c4572737db639653c29d3081d1d3e051467f00d7f09a776399?d=identicon)[xificurk](/maintainers/xificurk)

---

Top Contributors

[![xificurk](https://avatars.githubusercontent.com/u/117465?v=4)](https://github.com/xificurk "xificurk (7 commits)")

---

Tags

configurationenvironment-variablesmicroservicenette

### Embed Badge

![Health badge](/badges/damejidlo-envy/health.svg)

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

###  Alternatives

[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M575](/packages/nette-php-generator)[nette/robot-loader

🍀 Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

89152.7M320](/packages/nette-robot-loader)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M81](/packages/symplify-monorepo-builder)[nette/component-model

⚛ Nette Component Model

28516.5M90](/packages/nette-component-model)[nette/code-checker

✅ Nette CodeChecker: A simple tool to check source code against a set of Nette coding standards.

881.7M6](/packages/nette-code-checker)[contributte/di

Extra contrib to nette/di

465.8M18](/packages/contributte-di)

PHPackages © 2026

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