PHPackages                             pixelbrackets/application-context - 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. pixelbrackets/application-context

ActiveLibrary

pixelbrackets/application-context
=================================

Define the context of the current enviroment, in order to adapt configuration options depending on the stage an app is running on

1.1.0(6y ago)02.2k↓100%GPL-2.0-or-laterPHPPHP &gt;=7.0.0

Since Mar 21Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

Application Context
===================

[](#application-context)

[![Version](https://camo.githubusercontent.com/090b5916f4bd345392d699df19fc5394db1c385bcfa3846bc262a64a04cb4d7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706978656c627261636b6574732f6170706c69636174696f6e2d636f6e746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pixelbrackets/application-context/)[![Build Status](https://camo.githubusercontent.com/6435e6f9f6cecf6a8a42248e703d2fa5f9097f5df2f5232955e7d54316df23e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746c61622f706970656c696e652f706978656c627261636b6574732f6170706c69636174696f6e2d636f6e746578743f7374796c653d666c61742d737175617265)](https://gitlab.com/pixelbrackets/application-context/pipelines)[![Made With](https://camo.githubusercontent.com/f6c764778c46107383a50b589db66c3cdd5827e7414d138214e41a57ac94df33/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d6164655f776974682d7068702d626c75653f7374796c653d666c61742d737175617265)](https://gitlab.com/pixelbrackets/application-context#requirements)[![License](https://camo.githubusercontent.com/4daac00aaa49d8045d90fc294ffbcc993557bc747e009ca9b1e0bb5271dafa7d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d67706c2d2d322e302d2d6f722d2d6c617465722d626c75652e7376673f7374796c653d666c61742d737175617265)](https://spdx.org/licenses/GPL-2.0-or-later.html)

The »Application Context« library allows to define the context of the current environment, in order to adapt configuration options depending on the stage an app is running on.

For example if an application is running in `Production` mode, it should send mails and not create any log files. In `Development` mode however it should send mails, but to a different recipient, and create excessive log files.

```
export APPLICATION_CONTEXT=Development/Local/JohnDoe
```

```
if($applicationContext->isDevelopment()) {
    // … do this in development mode only
}
```

[An environment variable sets the context](https://12factor.net/config), whichs is retrieved using this class.

The main advantage of this approach is, that the code may stay the same on all stages, but only configuration values may change, depending on the context.

Requirements
------------

[](#requirements)

- PHP

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

[](#installation)

Packagist Entry

Source
------

[](#source)

Mirror

Usage
-----

[](#usage)

1. Set the application context using an environment variable

    A context may contain arbitrary sub-contexts. They are delimited with a slash. For example `Production/Integration` or `Development/LocalMachines/JohnDoe`.

    The top-level contexts however, must be one of `Development`, `Testing`or `Production`. `Testing` should be used to run unit tests only. Use `Production` and `Development` and any sub-context for all stages.

    ```
    export APPLICATION_CONTEXT=Development/Local/JohnDoe
    ```

    or pass to the script like this

    ```
    APPLICATION_CONTEXT=Development php index.php
    ```

    💡 Hint: The package [helhum/dotenv-connector](https://packagist.org/packages/helhum/dotenv-connector)lets you store these variables in an `.env` file and automatically parse it.
2. Integrate the `ApplicationContext` class

    ```
    $applicationContext = new \Pixelbrackets\ApplicationContext\ApplicationContext(getenv('APPLICATION_CONTEXT'));
    ```

    If the context variable is empty, then `Production` is the default.
3. Change code or configuration depending on the given context

    ```
    $config['write-logs'] = true;
    $config['mail']['to'] = 'johndoe@example.com';
    if($applicationContext->isDevelopment()) {
        $config['mail']['to'] = 'test-test@localhost.tld';
    }
    ```

    Available methods to check the top-level context are `isProduction()`, `isTesting()` and `isDevelopment()`.

    If the context object is casted to a string, then the return value is the context string as set in the environment variable. This may be used to load different files as in this example.

    ```
    $configFile = __DIR__ . '/Configuration/' . (string)$applicationContext . '.php';
    if (file_exists($configFile)) {
      require($configFile);
    }
    ```

License
-------

[](#license)

GNU General Public License version 2 or later

The GNU General Public License can be found at .

Attributions:

- This library is a standalone version of the Application Context in TYPO3 CMS which derived from the TYPO3 Flow framework.

Author
------

[](#author)

Dan Untenzu ( / [@pixelbrackets](https://pixelbrackets.de))

Changelog
---------

[](#changelog)

[./CHANGELOG.md](./CHANGELOG.md)

Contribution
------------

[](#contribution)

This script is Open Source, so please use, patch, extend or fork it.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

2194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ca67c6c7d79cf33bb5688dcbf217ad52309a52580b6a490aae8445f446178a3?d=identicon)[pixelbrackets](/maintainers/pixelbrackets)

---

Top Contributors

[![pixelbrackets](https://avatars.githubusercontent.com/u/1592995?v=4)](https://github.com/pixelbrackets "pixelbrackets (13 commits)")

---

Tags

application-contextconfigurationenvenvironmentphpstages

### Embed Badge

![Health badge](/badges/pixelbrackets-application-context/health.svg)

```
[![Health](https://phpackages.com/badges/pixelbrackets-application-context/health.svg)](https://phpackages.com/packages/pixelbrackets-application-context)
```

PHPackages © 2026

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