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
============

PHP application environment service

1.0.2(2y ago)149MITPHPPHP &gt;=8.1

Since Oct 5Pushed 2y 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 1mo ago

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

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

[](#php-appenv-service)

Allows you to do something special depending on the current environment.

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

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

3

Last Release

954d 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 (3 commits)")

---

Tags

phpappenvapp envapplication environment

### 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.

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

PHPackages © 2026

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