Download the PHP package pixelbrackets/application-context without Composer
On this page you can find all versions of the php package pixelbrackets/application-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pixelbrackets/application-context
More information about pixelbrackets/application-context
Files in pixelbrackets/application-context
Package application-context
Short Description Define the context of the current enviroment, in order to adapt configuration options depending on the stage an app is running on
License GPL-2.0-or-later
Informations about the package application-context
Application Context
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.
An environment variable sets the context, 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
- PHP
Installation
Packagist Entry https://packagist.org/packages/pixelbrackets/application-context/
Source
https://gitlab.com/pixelbrackets/application-context/
Mirror https://github.com/pixelbrackets/application-context/
Usage
-
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
orDevelopment/LocalMachines/JohnDoe
.The top-level contexts however, must be one of
Development
,Testing
orProduction
.Testing
should be used to run unit tests only. UseProduction
andDevelopment
and any sub-context for all stages.or pass to the script like this
💡 Hint: The package helhum/dotenv-connector lets you store these variables in an
.env
file and automatically parse it. -
Integrate the
ApplicationContext
classIf the context variable is empty, then
Production
is the default. -
Change code or configuration depending on the given context
Available methods to check the top-level context are
isProduction()
,isTesting()
andisDevelopment()
.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.
License
GNU General Public License version 2 or later
The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html.
Attributions:
- This library is a standalone version of the Application Context in TYPO3 CMS which derived from the TYPO3 Flow framework.
Author
Dan Untenzu (@pixelbrackets)
Changelog
./CHANGELOG.md
Contribution
This script is Open Source, so please use, patch, extend or fork it.