PHPackages                             k2gl/app-env - 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. k2gl/app-env

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

k2gl/app-env
============

Run code conditionally on the current application environment (prod, dev, test).

1.0.4(3w ago)13661MITPHPPHP &gt;=8.1CI passing

Since Oct 5Pushed 3w ago1 watchersCompare

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

READMEChangelogDependencies (9)Versions (6)Used By (1)

PHP AppEnv service
==================

[](#php-appenv-service)

[![CI](https://camo.githubusercontent.com/c746271c79e84cf822cf9a32815715d941cee152ff51a54d09d1f454eb5df8eb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b32676c2f6170702d656e762f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349266c6f676f3d676974687562)](https://github.com/k2gl/app-env/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/5c58f1d5a51ddc627e745dcbe251effd35c9f453fa5b3bfb724dc24de171cedf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b32676c2f6170702d656e763f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/k2gl/app-env)[![Total Downloads](https://camo.githubusercontent.com/687e3800771c177fe78226df5bb57c8024a5c4fc459262120ccbb171f72b11b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b32676c2f6170702d656e763f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/k2gl/app-env)[![PHPStan Level](https://camo.githubusercontent.com/01c58e66f2fafb70c17613ff2b1da3f549aade3a735b076da5cd9e5c04b945a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d3261356561373f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://phpstan.org)[![License](https://camo.githubusercontent.com/dc0389528c29abe2235938ead14149938658748bf7416d38023a7bac8d54ff25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b32676c2f6170702d656e763f636f6c6f723d79656c6c6f77677265656e)](https://packagist.org/packages/k2gl/app-env)

Run code conditionally on the current application environment (prod, dev, test).

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

[](#installation)

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require k2gl/app-env

```

Usage:
------

[](#usage)

```
enum AppEnvironment: string
{
    case DEV = 'dev';
    case TEST = 'test';
    case STAGE = 'stage';
    case PROD = 'prod';
}

use K2gl\Component\AppEnv\Services\AppEnv;

$appEnv = new AppEnv('test');

$appEnv->is('test'); // true
$appEnv->is(AppEnvironment::TEST); // true

$appEnv->not(AppEnvironment::TEST); // false
$appEnv->not('miss'); // true

$appEnv->in(['miss', 'kiss']); // false
$appEnv->in(['miss', 'test', 'kiss']); // true

$appEnv->notIn(['miss', 'kiss']); // true
$appEnv->notIn(['miss', 'test', 'kiss']); // false
```

Configuration as Symfony service
--------------------------------

[](#configuration-as-symfony-service)

Makes AppEnv available to be used as services in **services.yaml**

```
services:
    K2gl\Component\AppEnv\Services\AppEnv:
        arguments: ['%kernel.environment%']

```

Usage example:
--------------

[](#usage-example)

```
use K2gl\Component\AppEnv\Services\AppEnv;

class UserLoginProcessor
{
    public function __construct(
        private readonly AppEnv $appEnv,
    ) {
    }

    protected function getAuthenticationFailureResponse(AuthenticationException $exception): JsonResponse
    {
        $responseData = [ 'message' => 'Bad credentials' ];

        if ($this->appEnv->not(AppEnvironment::PROD)) {
            $responseData[ 'extended_message' ] = $exception->getMessage();
        }

        return new JsonResponse( data: $responseData, status: Response::HTTP_UNAUTHORIZED );
    }
}
```

Pull requests are always welcome
--------------------------------

[](#pull-requests-are-always-welcome)

[Collaborate with pull requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

Total

5

Last Release

23d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bc4aa529c7f13ea593297497f6eae20d5c07f476baa0a551960d7e6ff1e5413?d=identicon)[k2gl](/maintainers/k2gl)

---

Top Contributors

[![k2gl](https://avatars.githubusercontent.com/u/2846079?v=4)](https://github.com/k2gl "k2gl (11 commits)")

---

Tags

phpappenvapp envapplication environment

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/k2gl-app-env/health.svg)

```
[![Health](https://phpackages.com/badges/k2gl-app-env/health.svg)](https://phpackages.com/packages/k2gl-app-env)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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