PHPackages                             yatero/enivronment-picker - 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. yatero/enivronment-picker

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

yatero/enivronment-picker
=========================

Choose a labeled environment based on environment variables or URL.

v1.0.2(7y ago)013MITPHP

Since Feb 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yanosh-k/environment-picker)[ Packagist](https://packagist.org/packages/yatero/enivronment-picker)[ Docs](https://github.com/yanosh-k/environment-picker)[ RSS](/packages/yatero-enivronment-picker/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (4)Used By (0)

Environment Picker Class for PHP
================================

[](#environment-picker-class-for-php)

This class lets your applications determine which labeled environment is it running in, based on:

- an environment variable (detected with `getenv()`)
- a passed URL to the EnvironmentPicker::get() function
- the current URL (when not run trouh CLI)

Usage
=====

[](#usage)

By default, if an environment could not be determined from an environment variable or an URL, the class returns a default label, which is `production`.

Using host detection
--------------------

[](#using-host-detection)

Please note, that when using `EnvironmentPicker::get()` the `getenv()` value always gets precedence when both the environment value and labeled regex expressions are present.

```
$environments = array(
    'local'   => '/^(localhost(:{d}+)?)|(127\.0\.0\.1(:{d}+)?)$/i',
    'staging' => '/^(demo\.my-website\.com)|(8\.8\.8\.8)$/i'
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Returns the label of the environment for the current URL
\Yatero\EnvironmentPicker\EnvironmentPicker::get();

// Return the label of the environment for the given URL
\Yatero\EnvironmentPicker\EnvironmentPicker::get('https://demo.my-website.com/foo/bar');
```

Using a predefined environment value
------------------------------------

[](#using-a-predefined-environment-value)

You can set the environment variable in your server configurations, in your .htaccess file (if you are using Apache) or on runtime while calling `export ENGINE_ENV=staging`.

Be careful and initialize the allowed environments beforehand. By default only environments from the list are allowed as values. If you would like to allow `ENGINE_ENV`to take any value, you should call `EnvironmentPicker::strict(false)`

```
$environments = array(
    'local'   => null,
    'staging' => null
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Before getting the current environment make sure that you have the right variable name
\Yatero\EnvironmentPicker\EnvironmentPicker::envVarKey('MY_VAR');

\Yatero\EnvironmentPicker\EnvironmentPicker::get();
```

You can set labled regex values as a fallback, if the variable is not set or empty.

```
$environments = array(
    'local'   => '/^(localhost(:{d}+)?)|(127\.0\.0\.1(:{d}+)?)$/i',
    'staging' => '/^(demo\.my-website\.com)|(8\.8\.8\.8)$/i'
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Before getting the current environment make sure that you have the right variable name
\Yatero\EnvironmentPicker\EnvironmentPicker::envVarKey('MY_VAR');

\Yatero\EnvironmentPicker\EnvironmentPicker::get();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~11 days

Total

3

Last Release

2616d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed21217a0001d42192376838119dd5a5a90e6ad547b129ababe6edc31441687e?d=identicon)[yanosh-k](/maintainers/yanosh-k)

---

Top Contributors

[![yanosh-k](https://avatars.githubusercontent.com/u/13232800?v=4)](https://github.com/yanosh-k "yanosh-k (6 commits)")[![dfreerksen](https://avatars.githubusercontent.com/u/220746?v=4)](https://github.com/dfreerksen "dfreerksen (1 commits)")

---

Tags

urlenvironmentenv

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yatero-enivronment-picker/health.svg)

```
[![Health](https://phpackages.com/badges/yatero-enivronment-picker/health.svg)](https://phpackages.com/packages/yatero-enivronment-picker)
```

###  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)[imliam/laravel-env-set-command

Set a .env file variable from the command line

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

Laravel env helper commands

7855.4k](/packages/msztorc-laravel-env)[cekurte/environment

A library to get the values from environment variables and process to php data types

5884.0k7](/packages/cekurte-environment)[mirazmac/dotenvwriter

A PHP library to write values to .env (DotEnv) files

19129.3k7](/packages/mirazmac-dotenvwriter)

PHPackages © 2026

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