App Helper
There is an "app helper" class that provides access to any environmental variables set in the .env
file
as well as provides quick access to the current application object from anywhere in your application life cycle.
When an application object is created and bootstrapped, it is automatically registered with this static class.
use Pop\App;
$app = App::get(); // Returns the instance of the Pop\Application object
At anytime in the application life cycle, you can use the API of the app helper class to access environmental variables, like this:
use Pop\App;
if (App::env('SOME_VALUE') == 'foo') {
// Do something
}
Environment
The application environment variable sets what type of environment the current running app is in. Supported values
for the APP_ENV
variable are:
local
dev
testing
staging
production
(or justprod
)
use Pop\App;
if (App::isLocal()) {
// Do something in the local environment
} else if (App::isProduction()) {
// Do something in the production environment
}
Maintenance
The MAINTENANCE_MODE
variable can be set to either true
or false
to put the application into a controlled "down" state while upgrades and/or maintenance are being performed.
use Pop\App;
if (App::isDown()) {
// Handle the app in "maintenance mode"
}
The full API is:
App::config(?string $key = null)
App::name()
App::url()
App::env(string $key, mixed $default = null)
App::environment(mixed $env = null)
App::isLocal()
App::isDev()
App::isTesting()
App::isStaging()
App::isProduction()
App::isDown()
App::isUp()
And the above static methods are also available on the application object instance as well:
$app->name()
$app->url()
$app->env(string $key, mixed $default = null)
$app->environment(mixed $env = null)
$app->isLocal()
$app->isDev()
$app->isTesting()
$app->isStaging()
$app->isProduction()
$app->isDown()
$app->isUp()