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

ActiveLibrary

liftkit/environment-detection
=============================

A library for defining and detecting execution environments

v1.0.3(8y ago)0748↓100%LGPL-2.1-onlyPHP

Since Jul 6Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (5)Used By (0)

Environment Detection
=====================

[](#environment-detection)

A simple library to detect the environment your application is currently executing in.

Create a new Detector
---------------------

[](#create-a-new-detector)

```
use LiftKit\EnvironmentDetection\Detector;

$detector = new Detector;
```

Match HTTP\_HOST
----------------

[](#match-http_host)

Match the value is `$_SERVER['HTTP_HOST']`. This value is passed to php from the web server as the domain the request was sent to.

```
$detector->ifHttpHost('something.localhost', 'local')
	->ifHttpHost('test.something.com', 'test')
	->ifHttpHost('www.something.com', 'production')
	->ifHttpHost('*.something.com', 'subdomain')
	->ifHttpHost('*', 'default'); // if no other pattern matches

$environment = $detector->resolve();
```

`$environment` will equal one of `'development'`, `'test'`, `'production'`, '`subdomain`', or '`default`', depending on the host the application was accessed at. Note that `$_SERVER` will not be populated if the application was accessed via CLI. None of these will pass, and `$detector->resolve()` will return `null`.

Match the hostname of the current machine
-----------------------------------------

[](#match-the-hostname-of-the-current-machine)

This tests against the output of the command `uname -n` (or the equivalent `php_uname('n')`).

```
$detector->clear() // clear previous rules
	->ifHostName('*.local', 'local') // default pattern for macOS
	->ifHostName('*', 'default'); // will match all others

$environment = $detector->resolve();
```

Match an environment variable
-----------------------------

[](#match-an-environment-variable)

This test against a variable in `$_ENV`.

```
$detector->clear() // clear previous rules
	->ifEnv('environment', 'dev', 'local') // tests $_ENV['development'] == 'dev'
	->ifEnv('environment', '*', 'default'); // will match all values of $_ENV['environment'], if $_ENV['environment'] is defined

$environment = $detector->resolve();
```

Match an arbitrary value
------------------------

[](#match-an-arbitrary-value)

```
$detector->clear() // clear previous rules
	->ifMatch(php_uname('s'), 'Darwin', 'mac') // if macOS
	->ifMatch(php_uname('s'), 'Linux', 'linux'); // if Linux

$environment = $detector->resolve();
```

Note `php_uname('s')` reports the name of the operating system kernel.

Match a boolean expression and defaults
---------------------------------------

[](#match-a-boolean-expression-and-defaults)

```
$detector->clear() // clear previous rules
	->ifBool(defined('TEST_ENVIRONMENT'), 'test')
	->defaultTo('production'); // default value

$environment = $detector->resolve();
```

You can also mix and match conditions
-------------------------------------

[](#you-can-also-mix-and-match-conditions)

```
$detector->clear() // clear previous rules
	->ifMatch(php_sapi_name(), 'cli', 'cli') // in CLI
	->defaultTo('web'); // otherwise assume web request

$environment = $detector->resolve();
```

No matches
----------

[](#no-matches)

`$detector->resolve()` will return null if there is no default and no condition matches.

```
$detector->clear(); // clear previous rules

$environment = $detector->resolve(); // $environment === null
```

###  Health Score

30

—

LowBetter than 67% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Total

4

Last Release

2975d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d501887cec7d9f26e1b14f92b3759de77256f57e4dc00537507e94e25700560?d=identicon)[rwstream9](/maintainers/rwstream9)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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