{"id":20976902,"url":"https://github.com/pixelbrackets/application-context","last_synced_at":"2025-10-05T16:17:26.733Z","repository":{"id":57041999,"uuid":"126184171","full_name":"pixelbrackets/application-context","owner":"pixelbrackets","description":"Define the context of the current enviroment, in order to adapt configuration options depending on the stage an app is running on","archived":false,"fork":false,"pushed_at":"2020-05-06T11:50:07.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T18:29:37.301Z","etag":null,"topics":["application-context","configuration","env","environment","php","stages"],"latest_commit_sha":null,"homepage":"https://gitlab.com/pixelbrackets/application-context/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pixelbrackets.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T13:37:04.000Z","updated_at":"2020-11-13T14:55:56.000Z","dependencies_parsed_at":"2022-08-23T23:31:12.271Z","dependency_job_id":null,"html_url":"https://github.com/pixelbrackets/application-context","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbrackets%2Fapplication-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbrackets%2Fapplication-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbrackets%2Fapplication-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbrackets%2Fapplication-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixelbrackets","download_url":"https://codeload.github.com/pixelbrackets/application-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243381282,"owners_count":20281926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-context","configuration","env","environment","php","stages"],"created_at":"2024-11-19T04:56:16.854Z","updated_at":"2025-10-05T16:17:21.712Z","avatar_url":"https://github.com/pixelbrackets.png","language":"PHP","readme":"# Application Context\n\n[![Version](https://img.shields.io/packagist/v/pixelbrackets/application-context.svg?style=flat-square)](https://packagist.org/packages/pixelbrackets/application-context/)\n[![Build Status](https://img.shields.io/gitlab/pipeline/pixelbrackets/application-context?style=flat-square)](https://gitlab.com/pixelbrackets/application-context/pipelines)\n[![Made With](https://img.shields.io/badge/made_with-php-blue?style=flat-square)](https://gitlab.com/pixelbrackets/application-context#requirements)\n[![License](https://img.shields.io/badge/license-gpl--2.0--or--later-blue.svg?style=flat-square)](https://spdx.org/licenses/GPL-2.0-or-later.html)\n\nThe »Application Context« library allows to define the context of the current \nenvironment, in order to adapt configuration options depending on the stage \nan app is running on.\n\nFor example if an application is running in `Production` mode, it should\nsend mails and not create any log files. In `Development` mode however it \nshould send mails, but to a different recipient, and create excessive log files.\n\n```bash\nexport APPLICATION_CONTEXT=Development/Local/JohnDoe\n```\n```php\nif($applicationContext-\u003eisDevelopment()) {\n    // … do this in development mode only\n}\n```\n\n[An environment variable sets the context](https://12factor.net/config),\nwhichs is retrieved using this class.\n\nThe main advantage of this approach is, that the code may stay the same on all\nstages, but only configuration values may change, depending on the context.\n\n## Requirements\n\n- PHP\n\n## Installation\n\nPackagist Entry https://packagist.org/packages/pixelbrackets/application-context/\n\n## Source\n\nhttps://gitlab.com/pixelbrackets/application-context/\n\nMirror https://github.com/pixelbrackets/application-context/\n\n## Usage\n\n1. Set the application context using an environment variable\n\n   A context may contain arbitrary sub-contexts. They are delimited with\n   a slash. For example `Production/Integration` or \n   `Development/LocalMachines/JohnDoe`.\n\n   The top-level contexts however, must be one of `Development`, `Testing`\n   or `Production`. `Testing` should be used to run unit tests only.\n   Use `Production` and `Development` and any sub-context for all stages.\n\n   ```bash\n   export APPLICATION_CONTEXT=Development/Local/JohnDoe\n   ```\n   or pass to the script like this\n   ```bash\n   APPLICATION_CONTEXT=Development php index.php\n   ```\n\n   💡 Hint: The package [helhum/dotenv-connector](https://packagist.org/packages/helhum/dotenv-connector)\n   lets you store these variables in an `.env` file and automatically parse it.\n1. Integrate the `ApplicationContext` class\n   ```php\n   $applicationContext = new \\Pixelbrackets\\ApplicationContext\\ApplicationContext(getenv('APPLICATION_CONTEXT'));\n   ```\n\n   If the context variable is empty, then `Production` is the default.\n1. Change code or configuration depending on the given context\n   ```php\n   $config['write-logs'] = true;\n   $config['mail']['to'] = 'johndoe@example.com';\n   if($applicationContext-\u003eisDevelopment()) {\n       $config['mail']['to'] = 'test-test@localhost.tld';\n   }\n   ```\n\n   Available methods to check the top-level context are `isProduction()`, \n   `isTesting()` and `isDevelopment()`.\n   \n   If the context object is casted to a string, then the return value is the\n   context string as set in the environment variable. This may be used to load\n   different files as in this example.\n   ```php\n   $configFile = __DIR__ . '/Configuration/' . (string)$applicationContext . '.php';\n   if (file_exists($configFile)) {\n     require($configFile);\n   }\n   ```\n\n## License\n\nGNU General Public License version 2 or later\n\nThe GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html.\n\nAttributions:\n\n* This library is a standalone version of the Application Context in TYPO3 CMS\nwhich derived from the TYPO3 Flow framework.\n\n## Author\n\nDan Untenzu (\u003cmail@pixelbrackets.de\u003e / [@pixelbrackets](https://pixelbrackets.de))\n\n## Changelog\n\n[./CHANGELOG.md](./CHANGELOG.md)\n\n## Contribution\n\nThis script is Open Source, so please use, patch, extend or fork it.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbrackets%2Fapplication-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixelbrackets%2Fapplication-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbrackets%2Fapplication-context/lists"}