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

ActiveLibrary

monolyth/envy
=============

Flexible environment handler for PHP projects (including unit tests!)

0.7.7(1y ago)01.5k3MITPHPPHP &gt;=8.1

Since Sep 14Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (25)Used By (3)

Monolyth/Envy
=============

[](#monolythenvy)

Flexible environment handler for PHP projects (including unit tests!)

When writing PHP projects that are more complicated than a two-page site, you're going to run into some real life problems:

- Am I in development or production?

    E.g., during development a mailer should not actually send out mails to users, but instead proxy to the developer.
- What are the correct database credentials for this environment?

    Ideally, the same as production, but alas 'tis not an ideal world we live in.
- What are safe fallbacks for e.q. `$_SERVER` values when running from the command line?

    Since things like `$_SERVER['SERVER_NAME']` will also be different in development than they are in production.
- During testing, what should we use now?

    Obviously we don't want to test against a production database.
- How can I test a multi-project setup using one set of unit tests?

    PHPUnit and DBUnit are great, but they kinda assume a single database. For complex projects, this is often simply not the case. Also, multiple sites might be related and thus share 99% percent of unit tests. Since copy/paste is evil, it would be nice to have a way to automatically decide which database(s) a set of tests needs to run against.

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

[](#installation)

### Composer (recommended)

[](#composer-recommended)

```
$ composer require monolyth/envy
```

### Manual

[](#manual)

1. Download or clone the repository;
2. Add `/path/to/envy/src` for the namespace `Monolyth\\Envy\\` to your autoloader.

Usage
-----

[](#usage)

As of version 0.7, `Envy` works exclusively on `.env` files, since that seems to be the industry standard. We do still, however, support some extensions.

To construct your environment (somewhere centrally), instantiate an object of the `Monolyth\Envy\Environment` class. It takes two parameters: the path to your environment configuration files, and a hash where the keys are environment names and the values are either booleans or callables returning a boolean. Any environment that is or resolves to `false` will be skipped. Hence, you could do something like this:

```
